Created
March 9, 2009 08:54
-
-
Save yappo/76176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Foo.pm | |
package Foo; | |
sub say { print "Foo\n" } | |
1; | |
# Foo/Bar.pm | |
package Foo::Bar; | |
sub say { print "Foo::Bar\n" } | |
1; | |
# ok.pl | |
use strict; | |
use warnings; | |
use Class::MOP; | |
my $class; | |
$class = 'Foo::Bar'; | |
Class::MOP::load_class($class); | |
$class->say; # print 'Foo'; | |
$class = 'Foo'; | |
Class::MOP::load_class($class); | |
$class->say; # print 'Foo::Bar'; | |
__END__ | |
results: | |
Foo::Bar | |
Foo | |
# ng.pl | |
use strict; | |
use warnings; | |
use Class::MOP; | |
my $class; | |
$class = 'Foo::Bar'; | |
Class::MOP::load_class($class); | |
$class->say; # print 'Foo'; | |
$class = 'Foo'; | |
$class->can('say'); # add 'can' entry in GV stash? # MOP.xs Line 393 | |
Class::MOP::load_class($class); | |
$class->say; # NG | |
__END__ | |
results: | |
Foo::Bar | |
Can't locate object method "say" via package "Foo" at ./ng.pl line 14. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment