Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: REALLY Private Methods in perl: Is Perl Flexible enough to be made Inflexible?

by Zaxo (Archbishop)
on Sep 23, 2002 at 14:11 UTC ( #200102=note: print w/replies, xml ) Need Help??


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

  • Comment on Re: REALLY Private Methods in perl: Is Perl Flexible enough to be made Inflexible?
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2021-06-24 18:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (130 votes). Check out past polls.

    Notices?