in reply to Perl OO: Need a concise way of representing operations on an object
I think you can achieve what you’re looking for by using closures as follows:
{ my ($foo, $bar, $container); my %transformations = ( xform1 => sub { ... }, xform2 => sub { ... }, ); sub transform { (my $self, $container) = @_; for my $xform (@{$self->{xforms}}) { $foo = get_foo(); $bar = get_bar(); $transformations{$xform}->(); } } }
Using this approach, the anonymous subroutines (closures) in %transformations have access to $foo, $bar, and $container without the need for the boilerplate code.
Hope that helps,
Athanasius <°(((>< contra mundum
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl OO: Need a concise way of representing operations on an object
by wanna_code_perl (Friar) on Nov 04, 2012 at 09:05 UTC | |
by Athanasius (Archbishop) on Nov 04, 2012 at 14:45 UTC |