http://www.perlmonks.org?node_id=1002188


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.