Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • my $get = sub {
        my $self = shift;
        # do stuff

    # ...

    my $stuff = $self->$get( @whatever );
    • This is brilliant and clean, even if I'd say that I like to leave some space for people to shoot in their own feet, if they're keen to do so. Unless I'm mistaken, the only way for someone to really mess the:

            _get($self, %args);

      is by re-declaring the whole sub:

            no warnings 'redefine';
            sub That::Module::_get {
                  die "with pain";

      which is *way* far from what I consider "fair use of the _get symbol".

      Thank you for the suggestion, anyway :)
      • Well it’s not really about safety. It’s about namespacing. If you subclass another class, declaring a _get of your own is not safe because you don’t know whether the superclass has declared such a “private” method itself (or will declare one in a future version), and call it using $self->_get and thus accidentally invoke yours instead.

        Using lexicals ensures real encapsulation – not in the sense that you want to keep out people bent on getting in, but in the sense of

        • Uh, now I see: basically you're talking about a case in which my super-class provider hasn't taken the same care as me about his "private" methods. Which makes sense -- I only thought about it the day I posted it!