Stories
Slash Boxes
Comments
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.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • What I don’t see is why you picked closure-based objects?

    As for the package-per-instance approach, that works, but the packages never get garbage-collected unless you do that manually, which is tricky to get right in the best of cases, and I think deleting packages has some gotchas anyway.

    As for can, you know that it’s just a method, right? Assuming you use the first approach that relays through a dispatch table rather than the one where you create packages:

    sub can {
        my $self = shift;
        my ( $method ) = @_;
        return exists $self->{ $method }
            ? $self->{ $method }
            : $self->SUPER::can( $method );
    }

    (Employ SUPER [cpan.org] or Class::C3 [cpan.org] as appropriate.)

    That’s much neater than screwing around in the symbol tables.


    • As for why closure based objects, so that I didn't have to go through and change all of the thousands of variables to be $self{var} or $self->{var} or the like instead of $var.

      As for AUTOLOAD, that's a good point (redefining can). I'm not sure what I was thinking in just not doing that. But it's about the same amount of code either (mucking with the symbol table to redispatching with AUTOLOAD), and I like the idea of not having to go through AUTOLOAD for each hit.

      I'm probably going to be moving a lot o
      • Does the expense of going through AUTOLOAD really matter? Because it’s most definitely not the same amount of code, qualitatively speaking. The package-based code is a lot more conceptually complex, and has much more tangible problems than the overloaded can method (defies garbage collection vs. slows method calls down a tad).

        As for just changing the scope: what do you mean? I don’t quite understand that statement.