Subject: | Inconsistent handling of Foo::Bar, ::Foo::Bar, and main::Foo::Bar |
The following all basically work the same in Perl:
my $obj = 'Foo::Bar'->new;
my $obj = '::Foo::Bar'->new;
my $obj = 'main::Foo::Bar'->new;
Using any of those class names in $obj->isa works fine.
Moose breaks in various unpredictable ways using the '::Foo::Bar' and 'main::Foo::Bar' class names. Moo handles them somewhat better, but still not perfect.
Subject: | package-name-test.t |
use strict;
use warnings;
use Test::More;
{
package GGG;
use Moose::Role;
}
{
package Goose;
use Moose;
with 'GGG';
has 'goo' => ( is => 'ro' );
}
my @roles = qw( GGG ::GGG main::GGG );
my @classes = qw( Goose ::Goose main::Goose );
foreach my $class ( @classes ) {
subtest "\$class = '$class'" => sub {
ok( $class->meta->has_attribute('goo'), 'has_attribute' );
my $obj = $class->new( 'goo' => 42 );
is( $obj->goo, 42, '$obj->goo == 42' );
isa_ok( $obj, $_, '$obj' ) for @classes;
ok( $obj->DOES($_), "\$obj\->DOES($_)" ) for @roles;
ok( $obj->does($_), "\$obj\->does($_)" ) for @roles;
};
}
done_testing;