Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Moose: using value of one attribute in another attribute

by tobyink (Abbot)
on Jan 12, 2013 at 13:32 UTC ( #1013039=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Moose: using value of one attribute in another attribute
in thread Moose: using value of one attribute in another attribute

Perl doesn't have true private methods. Underscores are merely a convention to indicate that a sub is intended for internal use only.

It is possible to create do-it-yourself private subs by checking caller within a sub and then calling die if the caller is outside your module. Though this will have a performance impact if you do it a lot, and is of questionable benefit.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re^3: Moose: using value of one attribute in another attribute
Select or Download Code
Re^4: Moose: using value of one attribute in another attribute
by zwon (Monsignor) on Jan 13, 2013 at 06:32 UTC

    A simpler alternative to caller would be:

    my $private = sub { ... };

      True; that slipped my mind (even though I use the technique occasionally). These things are mostly circumventable (Scope::Upper for caller, PadWalker for lexical coderefs, etc), but perhaps the lexical subs coming in Perl 5.18 will be different.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2014-12-25 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls