Skip to content

Instantly share code, notes, and snippets.

@mash
Created August 21, 2012 11:24
Show Gist options
  • Save mash/3414679 to your computer and use it in GitHub Desktop.
Save mash/3414679 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
{
package Base;
use base qw/Class::Accessor::Fast/;
__PACKAGE__->mk_accessors( qw/name/ );
sub new {
my ( $class, %opts ) = @_;
bless { %opts }, $class;
}
}
{
package AutoloadedBase;
use base qw/Class::Accessor::Fast/;
__PACKAGE__->mk_accessors( qw/name/ );
sub new {
my ( $class, %opts ) = @_;
bless { %opts }, $class;
}
our $AUTOLOAD;
sub AUTOLOAD {
my $self = shift;
warn "called $AUTOLOAD";
0;
}
}
{
package Tester;
use Mouse::Role;
sub test {
return shift->name;
}
}
{
package Super;
use Mouse;
use MouseX::Foreign qw/Base/;
}
{
package AutoloadedSuper;
use Mouse;
use MouseX::Foreign qw/AutoloadedBase/;
}
my $a = Super->new( name => 'a' );
Tester->meta->apply( $a );
is( $a->test, 'a' );
my $b = AutoloadedSuper->new( name => 'b' );
Tester->meta->apply( $b );
is( $b->test, 'b' );
done_testing;
__END__
ok 1
called AutoloadedSuper::has_method at test.pl line 28.
called AutoloadedSuper::add_method at test.pl line 28.
called AutoloadedSuper::does_role at test.pl line 28.
called AutoloadedSuper::test at test.pl line 28.
not ok 2
# Failed test at test.pl line 59.
# got: '0'
# expected: 'b'
1..2
# Looks like you failed 1 test of 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment