Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by mimosinnet (Beadle)
on Jan 12, 2013 at 10:57 UTC ( [id://1013029]=note: print w/replies, xml ) Need Help??


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

Thanks very much for you clear and detailed answer! A good insight on how objects work! It is also very enlightening to understand your example on how to read the contents of the file. Also, I was not aware of the use of the underscore to make attributes and builders private!

Replies are listed 'Best First'.
Re^3: Moose: using value of one attribute in another attribute
by tobyink (Canon) on Jan 12, 2013 at 13:32 UTC

    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'

      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1013029]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-03-19 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found