Subject: | use Base not establishing ISA relationship within tests |
On SuSE Linux 9.3 (x86-64), the following tests were failing. It
appeared that perl wasn't looking for the invoked method in the parent
class.
I changed the relevent:
"use base 'packagename';"
lines to:
our @ISA; push @ISA, 'packagename';
and the tests passed. My versions of the tests and a diff file are
attached.
Does someone know if the test failing means that there really is
something wrong with Class::MOP, or just that inheritance needs to be
done a different way for this test maybe?
Thank you for your help. I know our version of SuSE is older, but
getting the tests to pass helps me encourage Moose adoption where I work :)
Thank you again,
Chris
--
christopher.nielsen@gmail.com
(347) 387-2328
<failing test lines>
t/015_metaclass_inheritance...............1/9 Can't locate object method
"meta" via package "Bar" at t/015_metaclass_inheritance.t line 32.
# Looks like you planned 9 tests but ran 2.
# Looks like your test exited with 255 just after 2.
t/102_InsideOutClass_test.................1/88 Can't locate object
method "new" via package "Bar" at t/102_InsideOutClass_test.t line 119.
# Looks like you planned 88 tests but ran 20.
# Looks like your test exited with 255 just after 20.
t/102_InsideOutClass_test................. Dubious, test returned 255
(wstat 65280, 0xff00)
Failed 68/88 subtests
t/108_ArrayBasedStorage_test..............1/72 Can't locate object
method "new" via package "Bar" at t/108_ArrayBasedStorage_test.t line 124.
# Looks like you planned 72 tests but ran 23.
# Looks like your test exited with 255 just after 23.
t/108_ArrayBasedStorage_test.............. Dubious, test returned 255
(wstat 65280, 0xff00)
Failed 49/72 subtests
</failing test lines>
Subject: | 108_ArrayBasedStorage_test.t |
use strict;
use warnings;
use Test::More tests => 72;
use File::Spec;
use Scalar::Util 'reftype';
BEGIN {use Class::MOP;
require_ok(File::Spec->catfile('examples', 'ArrayBasedStorage.pod'));
}
{
package Foo;
use strict;
use warnings;
use metaclass (
'instance_metaclass' => 'ArrayBasedStorage::Instance',
);
Foo->meta->add_attribute('foo' => (
accessor => 'foo',
clearer => 'clear_foo',
predicate => 'has_foo',
));
Foo->meta->add_attribute('bar' => (
reader => 'get_bar',
writer => 'set_bar',
default => 'FOO is BAR'
));
sub new {
my $class = shift;
$class->meta->new_object(@_);
}
package Bar;
use metaclass (
'instance_metaclass' => 'ArrayBasedStorage::Instance',
);
use strict;
use warnings;
our @ISA;
push @ISA, 'Foo';
Bar->meta->add_attribute('baz' => (
accessor => 'baz',
predicate => 'has_baz',
));
package Baz;
use metaclass (
'instance_metaclass' => 'ArrayBasedStorage::Instance',
);
use strict;
use warnings;
use metaclass (
'instance_metaclass' => 'ArrayBasedStorage::Instance',
);
Baz->meta->add_attribute('bling' => (
accessor => 'bling',
default => 'Baz::bling'
));
package Bar::Baz;
use metaclass (
'instance_metaclass' => 'ArrayBasedStorage::Instance',
);
use strict;
use warnings;
use base 'Bar', 'Baz';
}
my $foo = Foo->new();
isa_ok($foo, 'Foo');
is(reftype($foo), 'ARRAY', '... Foo is made with ARRAY');
can_ok($foo, 'foo');
can_ok($foo, 'has_foo');
can_ok($foo, 'get_bar');
can_ok($foo, 'set_bar');
can_ok($foo, 'clear_foo');
ok(!$foo->has_foo, '... Foo::foo is not defined yet');
is($foo->foo(), undef, '... Foo::foo is not defined yet');
is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
$foo->foo('This is Foo');
ok($foo->has_foo, '... Foo::foo is defined now');
is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
$foo->clear_foo;
ok(!$foo->has_foo, '... Foo::foo is not defined anymore');
is($foo->foo(), undef, '... Foo::foo is not defined anymore');
$foo->set_bar(42);
is($foo->get_bar(), 42, '... Foo::bar == 42');
my $foo2 = Foo->new();
isa_ok($foo2, 'Foo');
is(reftype($foo2), 'ARRAY', '... Foo is made with ARRAY');
ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
$foo2->set_bar('DONT PANIC');
is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
is($foo->get_bar(), 42, '... Foo::bar == 42');
# now Bar ...
my $bar = Bar->new();
isa_ok($bar, 'Bar');
isa_ok($bar, 'Foo');
is(reftype($bar), 'ARRAY', '... Bar is made with ARRAY');
can_ok($bar, 'foo');
can_ok($bar, 'has_foo');
can_ok($bar, 'get_bar');
can_ok($bar, 'set_bar');
can_ok($bar, 'baz');
can_ok($bar, 'has_baz');
ok(!$bar->has_foo, '... Bar::foo is not defined yet');
is($bar->foo(), undef, '... Bar::foo is not defined yet');
is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
ok(!$bar->has_baz, '... Bar::baz is not defined yet');
is($bar->baz(), undef, '... Bar::baz is not defined yet');
$bar->foo('This is Bar::foo');
ok($bar->has_foo, '... Bar::foo is defined now');
is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
$bar->baz('This is Bar::baz');
ok($bar->has_baz, '... Bar::baz is defined now');
is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
# now Baz ...
my $baz = Bar::Baz->new();
isa_ok($baz, 'Bar::Baz');
isa_ok($baz, 'Bar');
isa_ok($baz, 'Foo');
isa_ok($baz, 'Baz');
is(reftype($baz), 'ARRAY', '... Bar::Baz is made with ARRAY');
can_ok($baz, 'foo');
can_ok($baz, 'has_foo');
can_ok($baz, 'get_bar');
can_ok($baz, 'set_bar');
can_ok($baz, 'baz');
can_ok($baz, 'has_baz');
can_ok($baz, 'bling');
is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
$baz->foo('This is Bar::Baz::foo');
ok($baz->has_foo, '... Bar::Baz::foo is defined now');
is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
$baz->baz('This is Bar::Baz::baz');
ok($baz->has_baz, '... Bar::Baz::baz is defined now');
is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
Foo->meta->add_attribute( forgotten => is => "rw" );
my $new_baz = Bar::Baz->new;
cmp_ok( scalar(@$new_baz), ">", scalar(@$baz), "additional slot due to refreshed meta instance" );
Subject: | 102_InsideOutClass_test.t |
use strict;
use warnings;
use Test::More tests => 88;
use File::Spec;
use Scalar::Util 'reftype';
BEGIN {use Class::MOP;
require_ok(File::Spec->catfile('examples', 'InsideOutClass.pod'));
}
{
package Foo;
use strict;
use warnings;
use metaclass (
'attribute_metaclass' => 'InsideOutClass::Attribute',
'instance_metaclass' => 'InsideOutClass::Instance'
);
Foo->meta->add_attribute('foo' => (
accessor => 'foo',
predicate => 'has_foo',
));
Foo->meta->add_attribute('bar' => (
reader => 'get_bar',
writer => 'set_bar',
default => 'FOO is BAR'
));
sub new {
my $class = shift;
$class->meta->new_object(@_);
}
package Bar;
use metaclass (
'attribute_metaclass' => 'InsideOutClass::Attribute',
'instance_metaclass' => 'InsideOutClass::Instance'
);
use strict;
use warnings;
our @ISA;
push @ISA, 'Foo';
Bar->meta->add_attribute('baz' => (
accessor => 'baz',
predicate => 'has_baz',
));
package Baz;
use strict;
use warnings;
use metaclass (
'attribute_metaclass' => 'InsideOutClass::Attribute',
'instance_metaclass' => 'InsideOutClass::Instance'
);
Baz->meta->add_attribute('bling' => (
accessor => 'bling',
default => 'Baz::bling'
));
package Bar::Baz;
use metaclass (
'attribute_metaclass' => 'InsideOutClass::Attribute',
'instance_metaclass' => 'InsideOutClass::Instance'
);
use strict;
use warnings;
use base 'Bar', 'Baz';
}
my $foo = Foo->new();
isa_ok($foo, 'Foo');
is(reftype($foo), 'SCALAR', '... Foo is made with SCALAR');
can_ok($foo, 'foo');
can_ok($foo, 'has_foo');
can_ok($foo, 'get_bar');
can_ok($foo, 'set_bar');
ok(!$foo->has_foo, '... Foo::foo is not defined yet');
is($foo->foo(), undef, '... Foo::foo is not defined yet');
is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
$foo->foo('This is Foo');
ok($foo->has_foo, '... Foo::foo is defined now');
is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
$foo->set_bar(42);
is($foo->get_bar(), 42, '... Foo::bar == 42');
my $foo2 = Foo->new();
isa_ok($foo2, 'Foo');
is(reftype($foo2), 'SCALAR', '... Foo is made with SCALAR');
ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
$foo2->set_bar('DONT PANIC');
is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
is($foo->get_bar(), 42, '... Foo::bar == 42');
# now Bar ...
my $bar = Bar->new();
isa_ok($bar, 'Bar');
isa_ok($bar, 'Foo');
is(reftype($bar), 'SCALAR', '... Bar is made with SCALAR');
can_ok($bar, 'foo');
can_ok($bar, 'has_foo');
can_ok($bar, 'get_bar');
can_ok($bar, 'set_bar');
can_ok($bar, 'baz');
can_ok($bar, 'has_baz');
ok(!$bar->has_foo, '... Bar::foo is not defined yet');
is($bar->foo(), undef, '... Bar::foo is not defined yet');
is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
ok(!$bar->has_baz, '... Bar::baz is not defined yet');
is($bar->baz(), undef, '... Bar::baz is not defined yet');
$bar->foo('This is Bar::foo');
ok($bar->has_foo, '... Bar::foo is defined now');
is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
$bar->baz('This is Bar::baz');
ok($bar->has_baz, '... Bar::baz is defined now');
is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
# now Baz ...
my $baz = Bar::Baz->new();
isa_ok($baz, 'Bar::Baz');
isa_ok($baz, 'Bar');
isa_ok($baz, 'Foo');
isa_ok($baz, 'Baz');
is(reftype($baz), 'SCALAR', '... Bar::Baz is made with SCALAR');
can_ok($baz, 'foo');
can_ok($baz, 'has_foo');
can_ok($baz, 'get_bar');
can_ok($baz, 'set_bar');
can_ok($baz, 'baz');
can_ok($baz, 'has_baz');
can_ok($baz, 'bling');
is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
$baz->foo('This is Bar::Baz::foo');
ok($baz->has_foo, '... Bar::Baz::foo is defined now');
is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
$baz->baz('This is Bar::Baz::baz');
ok($baz->has_baz, '... Bar::Baz::baz is defined now');
is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
{
no strict 'refs';
ok(*{'Foo::foo'}{HASH}, '... there is a foo package variable in Foo');
ok(*{'Foo::bar'}{HASH}, '... there is a bar package variable in Foo');
is(scalar(keys(%{'Foo::foo'})), 4, '... got the right number of entries for Foo::foo');
is(scalar(keys(%{'Foo::bar'})), 4, '... got the right number of entries for Foo::bar');
ok(!*{'Bar::foo'}{HASH}, '... no foo package variable in Bar');
ok(!*{'Bar::bar'}{HASH}, '... no bar package variable in Bar');
ok(*{'Bar::baz'}{HASH}, '... there is a baz package variable in Bar');
is(scalar(keys(%{'Bar::foo'})), 0, '... got the right number of entries for Bar::foo');
is(scalar(keys(%{'Bar::bar'})), 0, '... got the right number of entries for Bar::bar');
is(scalar(keys(%{'Bar::baz'})), 2, '... got the right number of entries for Bar::baz');
ok(*{'Baz::bling'}{HASH}, '... there is a bar package variable in Baz');
is(scalar(keys(%{'Baz::bling'})), 1, '... got the right number of entries for Baz::bling');
ok(!*{'Bar::Baz::foo'}{HASH}, '... no foo package variable in Bar::Baz');
ok(!*{'Bar::Baz::bar'}{HASH}, '... no bar package variable in Bar::Baz');
ok(!*{'Bar::Baz::baz'}{HASH}, '... no baz package variable in Bar::Baz');
ok(!*{'Bar::Baz::bling'}{HASH}, '... no bar package variable in Baz::Baz');
is(scalar(keys(%{'Bar::Baz::foo'})), 0, '... got the right number of entries for Bar::Baz::foo');
is(scalar(keys(%{'Bar::Baz::bar'})), 0, '... got the right number of entries for Bar::Baz::bar');
is(scalar(keys(%{'Bar::Baz::baz'})), 0, '... got the right number of entries for Bar::Baz::baz');
is(scalar(keys(%{'Bar::Baz::bling'})), 0, '... got the right number of entries for Bar::Baz::bling');
}
Subject: | 015_metaclass_inheritance.t |
use strict;
use warnings;
use Test::More tests => 9;
use Test::Exception;
use Class::MOP;
=pod
Test that a default set up will cause metaclasses to inherit
the same metaclass type, but produce different metaclasses.
=cut
{
package Foo;
use metaclass;
package Bar;
our @ISA = ('Foo');
package Baz;
our @ISA = ('Bar');
}
my $foo_meta = Foo->meta;
isa_ok($foo_meta, 'Class::MOP::Class');
is($foo_meta->name, 'Foo', '... foo_meta->name == Foo');
my $bar_meta = Bar->meta;
isa_ok($bar_meta, 'Class::MOP::Class');
is($bar_meta->name, 'Bar', '... bar_meta->name == Bar');
isnt($bar_meta, $foo_meta, '... Bar->meta != Foo->meta');
my $baz_meta = Baz->meta;
isa_ok($baz_meta, 'Class::MOP::Class');
is($baz_meta->name, 'Baz', '... baz_meta->name == Baz');
isnt($baz_meta, $bar_meta, '... Baz->meta != Bar->meta');
isnt($baz_meta, $foo_meta, '... Baz->meta != Foo->meta');
Subject: | test.diff |
diff /home/cnielsen/Class-MOP-0.81-XgkZ54/t/015_metaclass_inheritance.t ./015_metaclass_inheritance.t
21c21
< our @ISA = ('Foo');
---
> use base 'Foo';
24c24
< our @ISA = ('Bar');
---
> use base 'Bar';
diff /home/cnielsen/Class-MOP-0.81-XgkZ54/t/102_InsideOutClass_test.t ./102_InsideOutClass_test.t
48,49c48
< our @ISA;
< push @ISA, 'Foo';
---
> use base 'Foo';
diff /home/cnielsen/Class-MOP-0.81-XgkZ54/t/108_ArrayBasedStorage_test.t ./108_ArrayBasedStorage_test.t
46,47c46
< our @ISA;
< push @ISA, 'Foo';
---
> use base 'Foo';
Common subdirectories: /home/cnielsen/Class-MOP-0.81-XgkZ54/t/lib and ./lib