Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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 surveying the Monastery: (6)
As of 2015-08-01 01:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls