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

Yeah, I agree that relying on convention to mark 'private' subs is somewhat lackluster. This approach is really interesting.

This is very interesting. I wonder why the ugly mega-sigil is required, though. I can't think of a good reason to disallow the $self->lexical_sub() syntax.

Replies are listed 'Best First'.
Re^2: Real private methods using lexical subs in Perl 5.18.
by LanX (Saint) on Jun 01, 2013 at 08:51 UTC
    > 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)