}
{
package Diamond_C;
- use base 'Diamond_A';
+ use base 'Diamond_A';
}
{
package Diamond_D;
{
package Test::O;
our @ISA = qw//;
-
- package Test::F;
- use base 'Test::O';
-
+
+ package Test::F;
+ use base 'Test::O';
+
package Test::E;
- use base 'Test::O';
-
+ use base 'Test::O';
+
package Test::D;
- use base 'Test::O';
-
+ use base 'Test::O';
+
package Test::C;
use base ('Test::D', 'Test::F');
-
- package Test::B;
- use base ('Test::D', 'Test::E');
-
- package Test::A;
+
+ package Test::B;
+ use base ('Test::D', 'Test::E');
+
+ package Test::A;
use base ('Test::B', 'Test::C');
}
is_deeply(
[ Class::C3::XS::calculateMRO('Test::E') ],
[ qw(Test::E Test::O) ],
- '... got the right MRO for Test::E');
+ '... got the right MRO for Test::E');
is_deeply(
[ Class::C3::XS::calculateMRO('Test::D') ],
[ qw(Test::D Test::O) ],
- '... got the right MRO for Test::D');
+ '... got the right MRO for Test::D');
is_deeply(
[ Class::C3::XS::calculateMRO('Test::C') ],
[ qw(Test::C Test::D Test::F Test::O) ],
- '... got the right MRO for Test::C');
+ '... got the right MRO for Test::C');
is_deeply(
[ Class::C3::XS::calculateMRO('Test::B') ],
[ qw(Test::B Test::D Test::E Test::O) ],
- '... got the right MRO for Test::B');
+ '... got the right MRO for Test::B');
is_deeply(
[ Class::C3::XS::calculateMRO('Test::A') ],
[ qw(Test::A Test::B Test::C Test::D Test::E Test::F Test::O) ],
- '... got the right MRO for Test::A');
-
+ '... got the right MRO for Test::A');
{
package Test::O;
our @ISA = qw//;
-
+
package Test::F;
use base 'Test::O';
-
+
package Test::E;
use base 'Test::O';
-
+
package Test::D;
- use base 'Test::O';
-
+ use base 'Test::O';
+
package Test::C;
use base ('Test::D', 'Test::F');
package Test::B;
use base ('Test::E', 'Test::D');
-
+
package Test::A;
use base ('Test::B', 'Test::C');
}
is_deeply(
[ Class::C3::XS::calculateMRO('Test::A') ],
[ qw(Test::A Test::B Test::E Test::C Test::D Test::F Test::O) ],
- '... got the right MRO for Test::A');
+ '... got the right MRO for Test::A');
Object
^
|
- LifeForm
+ LifeForm
^ ^
/ \
Sentient BiPedal
=cut
{
- package Object;
+ package Object;
our @ISA = qw//;
-
+
package LifeForm;
use base 'Object';
-
+
package Sentient;
use base 'LifeForm';
-
+
package BiPedal;
use base 'LifeForm';
-
+
package Intelligent;
use base 'Sentient';
-
+
package Humanoid;
use base 'BiPedal';
-
+
package Vulcan;
use base ('Intelligent', 'Humanoid');
}
is_deeply(
[ Class::C3::XS::calculateMRO('Vulcan') ],
[ qw(Vulcan Intelligent Sentient Humanoid BiPedal LifeForm Object) ],
- '... got the right MRO for the Vulcan Dylan Example');
+ '... got the right MRO for the Vulcan Dylan Example');
{
package Diamond_A;
sub hello { 'Diamond_A::hello' }
- sub foo { 'Diamond_A::foo' }
+ sub foo { 'Diamond_A::foo' }
}
{
package Diamond_B;
use base 'Diamond_A';
- sub foo { 'Diamond_B::foo => ' . (shift)->next::method() }
+ sub foo { 'Diamond_B::foo => ' . (shift)->next::method() }
}
{
package Diamond_C;
- use base 'Diamond_A';
+ use base 'Diamond_A';
sub hello { 'Diamond_C::hello => ' . (shift)->next::method() }
- sub foo { 'Diamond_C::foo => ' . (shift)->next::method() }
+ sub foo { 'Diamond_C::foo => ' . (shift)->next::method() }
}
{
package Diamond_D;
use base ('Diamond_B', 'Diamond_C');
-
- sub foo { 'Diamond_D::foo => ' . (shift)->next::method() }
+
+ sub foo { 'Diamond_D::foo => ' . (shift)->next::method() }
}
is(Diamond_C->hello, 'Diamond_C::hello => Diamond_A::hello', '... method resolved itself as expected');
-is(Diamond_C->can('hello')->('Diamond_C'),
- 'Diamond_C::hello => Diamond_A::hello',
+is(Diamond_C->can('hello')->('Diamond_C'),
+ 'Diamond_C::hello => Diamond_A::hello',
'... can(method) resolved itself as expected');
-
-is(UNIVERSAL::can("Diamond_C", 'hello')->('Diamond_C'),
- 'Diamond_C::hello => Diamond_A::hello',
+
+is(UNIVERSAL::can("Diamond_C", 'hello')->('Diamond_C'),
+ 'Diamond_C::hello => Diamond_A::hello',
'... can(method) resolved itself as expected');
-is(Diamond_D->foo,
- 'Diamond_D::foo => Diamond_B::foo => Diamond_C::foo => Diamond_A::foo',
+is(Diamond_D->foo,
+ 'Diamond_D::foo => Diamond_B::foo => Diamond_C::foo => Diamond_A::foo',
'... method foo resolved itself as expected');
{
package Diamond_A;
- sub bar { 'Diamond_A::bar' }
+ sub bar { 'Diamond_A::bar' }
sub baz { 'Diamond_A::baz' }
}
{
package Diamond_B;
use base 'Diamond_A';
- sub baz { 'Diamond_B::baz => ' . (shift)->next::method() }
+ sub baz { 'Diamond_B::baz => ' . (shift)->next::method() }
}
{
package Diamond_C;
- use base 'Diamond_A';
- sub foo { 'Diamond_C::foo' }
- sub buz { 'Diamond_C::buz' }
-
+ use base 'Diamond_A';
+ sub foo { 'Diamond_C::foo' }
+ sub buz { 'Diamond_C::buz' }
+
sub woz { 'Diamond_C::woz' }
- sub maybe { 'Diamond_C::maybe' }
+ sub maybe { 'Diamond_C::maybe' }
}
{
package Diamond_D;
use base ('Diamond_B', 'Diamond_C');
- sub foo { 'Diamond_D::foo => ' . (shift)->next::method() }
- sub bar { 'Diamond_D::bar => ' . (shift)->next::method() }
- sub buz { 'Diamond_D::buz => ' . (shift)->baz() }
- sub fuz { 'Diamond_D::fuz => ' . (shift)->next::method() }
-
+ sub foo { 'Diamond_D::foo => ' . (shift)->next::method() }
+ sub bar { 'Diamond_D::bar => ' . (shift)->next::method() }
+ sub buz { 'Diamond_D::buz => ' . (shift)->baz() }
+ sub fuz { 'Diamond_D::fuz => ' . (shift)->next::method() }
+
sub woz { 'Diamond_D::woz can => ' . ((shift)->next::can() ? 1 : 0) }
sub noz { 'Diamond_D::noz can => ' . ((shift)->next::can() ? 1 : 0) }
sub maybe { 'Diamond_D::maybe => ' . ((shift)->maybe::next::method() || 0) }
- sub moybe { 'Diamond_D::moybe => ' . ((shift)->maybe::next::method() || 0) }
+ sub moybe { 'Diamond_D::moybe => ' . ((shift)->maybe::next::method() || 0) }
}
isa_ok($foo, 'Foo');
can_ok($foo, 'bar');
- is($foo->bar(), 'Foo::bar', '... got the right return value');
+ is($foo->bar(), 'Foo::bar', '... got the right return value');
# fail calling it from a subclass
use strict;
use warnings;
our @ISA = ('Foo');
- }
-
+ }
+
my $bar = Bar->new();
isa_ok($bar, 'Bar');
- isa_ok($bar, 'Foo');
-
+ isa_ok($bar, 'Foo');
+
# test it working with with Sub::Name
- SKIP: {
+ SKIP: {
eval 'use Sub::Name';
skip "Sub::Name is required for this test", 3 if $@;
-
+
my $m = sub { (shift)->next::method() };
Sub::Name::subname('Bar::bar', $m);
{
ok(!$@, '... calling bar() succedded') || diag $@;
is($value, 'Foo::bar', '... got the right return value too');
}
-
+
# test it failing without Sub::Name
{
package Baz;
use strict;
use warnings;
our @ISA = ('Foo');
- }
-
+ }
+
my $baz = Baz->new();
isa_ok($baz, 'Baz');
- isa_ok($baz, 'Foo');
-
+ isa_ok($baz, 'Foo');
+
{
my $m = sub { (shift)->next::method() };
{
eval { $baz->bar() };
ok($@, '... calling bar() with next::method failed') || diag $@;
- }
+ }
}
package Foo;
use strict;
use warnings;
-
+
sub foo { 'Foo::foo' }
-
+
package Fuz;
use strict;
use warnings;
use base 'Foo';
sub foo { 'Fuz::foo => ' . (shift)->next::method }
-
+
package Bar;
use strict;
- use warnings;
+ use warnings;
use base 'Foo';
sub foo { 'Bar::foo => ' . (shift)->next::method }
-
+
package Baz;
use strict;
- use warnings;
+ use warnings;
require NEXT; # load this as late as possible so we can catch the test skip
use base 'Bar', 'Fuz';
-
- sub foo { 'Baz::foo => ' . (shift)->NEXT::foo }
+
+ sub foo { 'Baz::foo => ' . (shift)->NEXT::foo }
}
is(Foo->foo, 'Foo::foo', '... got the right value from Foo->foo');
{
package B;
use base 'A';
-
+
sub foo {
eval {
return 'B::foo => ' . (shift)->next::method();
}
}
-like(B->foo,
- qr/^A::foo died/,
+like(B->foo,
+ qr/^A::foo died/,
'method resolved inside eval{}');
{
package B;
use base 'A';
-
+
sub foo {
my $code = sub {
return 'B::foo => ' . (shift)->next::method();