Don't ask to ask, just ask | |
PerlMonks |
Re^2: Real private methods using lexical subs in Perl 5.18.by LanX (Saint) |
on Jun 01, 2013 at 08:51 UTC ( [id://1036399]=note: print w/replies, xml ) | Need Help?? |
> This is very interesting. I wonder why the ugly mega-sigil is required The mega-sigil is actually a workaround to call the lexical sub as a code-ref like described in the update. Keep in mind that for Perl the names in method calls are syntactically literal strings messaged to the object. And literal strings can't be scoped. I.a.W. Perl can't tell if you call $obj->private within the package/class or not. But generally allowing it fundamentally violates the definition of privacy. Calling $obj->$code_ref doesn't have this limitation, cause scalars can be lexically scoped.
Cheers Rolf ( addicted to the Perl Programming Language)
In Section
Meditations
|
|