Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Perl OO: Need a concise way of representing operations on an object

by Jenda (Abbot)
on Nov 04, 2012 at 11:51 UTC ( #1002188=note: print w/ replies, xml ) Need Help??


in reply to Perl OO: Need a concise way of representing operations on an object

The objects are irrelevant in this case.

Maybe it'd be enough to local()ize the variables instead of insisting that they are lexical:

{ our ($cont, $foo, $bar); my %transformations = ( xxx => sub { use_the($foo,'and', $bar); as_you_need($cont); }, ... ); } ... for my $xform (@{$self->{xforms}}) { our ($cont, $foo, $bar); local $foo = get_foo(); local $bar = get_bar(); local $cont = $container; $transformations{$xform}->(); }

I would not bother and just access $_[0], $_[1] and $_[2] within the transformations.

The only other option is a source filter and I bet you don't want to go there.

Jenda
Enoch was right!
Enjoy the last years of Rome.


Comment on Re: Perl OO: Need a concise way of representing operations on an object
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (20)
As of 2015-07-07 21:47 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 (93 votes), past polls