in reply to Re^2: Detecting which class a method is defined in
in thread Detecting which class a method is defined in

No, this is all compiled in main:
#!perl -l $y='main';$A::y='A';$C::y='C'; sub A::foo { $y } sub A::bar { $y } @C::ISA = 'A'; sub C::bar { $y } use B 'svref_2object'; $x = bless {}, 'C'; for (qw(foo bar)) { print "$_ -> ", $x->$_, " from ", svref_2object(UNIVERSAL::can($x, + $_))->GV->STASH->NAME; }
I guess the role and mixin stuff on CPAN must do something else if it breaks this.

Replies are listed 'Best First'.
Re^4: Detecting which class a method is defined in
by chromatic (Archbishop) on May 05, 2011 at 22:00 UTC

    I mean this behavior:

    #!/usr/bin/perl -l $y='main';$A::y='A';$C::y='C'; package main; sub foo { $y } sub bar { $y } package A; *foo = \&main::foo; *bar = \&main::bar; package C; @C::ISA = 'A'; *bar = \&main::bar; package main; use B 'svref_2object'; my $x = bless {}, 'C'; for (qw(foo bar)) { print "$_ -> ", $x->$_, " from ", svref_2object(UNIVERSAL::can($x, + $_))->GV->STASH->NAME; }

    If you know the name of the intended destination stash at the time of writing the code, your example works fine. It's not always possible to know that, unfortunately.