develooper Front page | perl.perl5.porters | Postings from August 2008

no overloading;

Thread Next
From:
Yuval Kogman
Date:
August 6, 2008 05:07
Subject:
no overloading;
Message ID:
20080806120652.GE22989@woobling.org
Hello,

often times it's very useful to locally disable overloading (to
avoid side effects or in the implementation of the overloads'
implementation code itself).

Unfortunately the only way I know to achieve that is doing something
like:
	
	my $class = blessed $obj;
	bless $obj, "no_overload";

	...

	bless $obj, $class;

but this totally violates the object's encapsulation by removing all
of its behavior.

I think a much more attractive solution would be an 'overload'
pragma that can lexically disable overloading of a certain op or
alltogether:

	use overload '%{}' => sub {
		no overloading;
		$_[0]{foo}; # doesn't infinitely recurse
	};

this will also make Ricardo's method dispatch overloading a lot more
usable.

Thoughts?

-- 
  Yuval Kogman <nothingmuch@woobling.org>
http://nothingmuch.woobling.org  0xEBD27418


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About