develooper Front page | perl.perl5.porters | Postings from September 2000

Perl5.7.0 "overload" of %{}

Thread Next
Nick Ing-Simmons
September 2, 2000 07:16
Perl5.7.0 "overload" of %{}
Message ID:

Continuing my testing of 5.7.0 I just tried a day-job OO + overload

It uses overload to build "parse trees" - Damian knows what I mean.

It exploded in deep recursion because the 'nomethod' overload
was triggered for %{}. 

This is definitly a trap. 

My object(s) are hashes. So they access their guts with 


- but that triggers the overload so to avoid 
triggering the 'nomethod' I need to define %{} but I DON'T WANT to!
I don't need any MORE overhead accessing my internals!!!

The suggested method of handling this is horrible:

     sub access_hash {
           my ($self, $key) = (shift, shift);
           my $class = ref $self;
           bless $self, 'overload::dummy'; # Disable overloading of %{}
           my $out = $self->{$key};
           bless $self, $class;        # Restore overloading

What happens when I say 

  $obj->{'key'} = something;

How does "access_hash" above work in that case?

May I humbly suggest that %{} & other derefs should _NOT_ 
be passed to 'nomethod' ?

Or some way of saying don't overload a particular operator perhaps:

  '%{}' => undef, 

Sigh, and just when I thought there would be a 5.6+ I could _deploy_.

Nick Ing-Simmons

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About