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

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Wednesday April 18, 2007
04:25 AM

Not for everyone

[ #33018 ]

package My::Can;

use strict;
use warnings;
use Sub::Identify 'stash_name';

use base 'Exporter';

our @EXPORT = qw(CAN can);

sub CAN {
    my ( $proto, $method ) = @_;
    $proto->SUPER::can($method);
}

sub can {
    my ( $proto, $method ) = @_;
    return if '_' eq substr $method, 0, 1;   # season to taste

    my $coderef        = $proto->SUPER::can($method) or return;
    my $source_package = stash_name($coderef)        or return;
    return $coderef if $proto->isa($source_package);
}

1;

Update:: smylers just pointed out the bug. Do you see it? (Yes, this can fail with traits and mixins if they're not implemented carefully, but that's not the obvious issue that smylers pointed out).

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.
  • I assume you mean the fact that SUPER relies on the compile-time package that a function is in.

    • Um, er, uh. No. But now that you mention it, my code is giving me pause. I'll have to look at my tests again. It passes them and I checked that. Now I'm a wee bit confused as to how my tests passed.