in reply to Re: Real private methods using lexical subs in Perl 5.18.
in thread Real private methods using lexical subs in Perl 5.18.

> 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)