in reply to REALLY Private Methods in perl: Is Perl Flexible enough to be made Inflexible?
Sure, closures, the same technique that's used to make other lexicals really private, can be used for anonymous subroutines:
{ my $private_method = { foo => sub { stuff }, bar => sub { mostuff }, }; sub public_method { my @args = @_; $private_method->{foo}(@args); $private_method->{bar}(@args); } }
The references within public_method keep the lexical $private_method alive after the name has gone out of scope.
After Compline,
Zaxo
|
---|