Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Rea: Invoke object methods with a symbolic reference

by baku (Scribe)
on Feb 14, 2001 at 19:59 UTC ( #58365=note: print w/ replies, xml ) Need Help??


in reply to Re: Invoke object methods with a symbolic reference
in thread Invoke object methods with a symbolic reference

You could do the same by generating a closure to pass it $a == $self:

sub new { my $self = {}; bless $self, $_[0]; $self->{f} = sub { &foo ($self, @_); }; return $self; }

The only reason for the three-line form with temporary variable is that I can't figure out how else to embed the closure "reference" to the object ($self) inside of an hash inside of the object itself :-)

(fixed minor typo!)


Comment on Rea: Invoke object methods with a symbolic reference
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://58365]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-10-26 01:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls