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

Perl5.7.0 "overload" of %{}

Thread Next
From:
Nick Ing-Simmons
Date:
September 2, 2000 07:16
Subject:
Perl5.7.0 "overload" of %{}
Message ID:
E13VDvf-0000vF-00@roam1

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

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 

$obj->{'key'} 

- 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
           $out;
         }          

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


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