Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 imbibing at the Monastery: (5)
As of 2014-07-29 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (212 votes), past polls