DEATH TO ALL zionist ELLIPSES
[gitmo/Moose.git] / t / 010_basics / 003_super_and_override.t
CommitLineData
b6fe348f 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
7ff56534 6use Test::More tests => 16;
d05cd563 7use Test::Exception;
b6fe348f 8
7ff56534 9
b6fe348f 10
11{
12 package Foo;
b6fe348f 13 use Moose;
d03bd989 14
b6fe348f 15 sub foo { 'Foo::foo' }
d03bd989 16 sub bar { 'Foo::bar' }
b6fe348f 17 sub baz { 'Foo::baz' }
d03bd989 18
b6fe348f 19 package Bar;
b6fe348f 20 use Moose;
d03bd989 21
b6fe348f 22 extends 'Foo';
d03bd989 23
24 override bar => sub { 'Bar::bar -> ' . super() };
25
b6fe348f 26 package Baz;
b6fe348f 27 use Moose;
d03bd989 28
b6fe348f 29 extends 'Bar';
d03bd989 30
31 override bar => sub { 'Baz::bar -> ' . super() };
32 override baz => sub { 'Baz::baz -> ' . super() };
52c7c330 33
34 no Moose; # ensure super() still works after unimport
b6fe348f 35}
36
37my $baz = Baz->new();
38isa_ok($baz, 'Baz');
39isa_ok($baz, 'Bar');
40isa_ok($baz, 'Foo');
41
1808c2da 42is($baz->foo(), 'Foo::foo', 'got the right value from &foo');
43is($baz->bar(), 'Baz::bar -> Bar::bar -> Foo::bar', 'got the right value from &bar');
44is($baz->baz(), 'Baz::baz -> Foo::baz', 'got the right value from &baz');
159da176 45
46my $bar = Bar->new();
47isa_ok($bar, 'Bar');
48isa_ok($bar, 'Foo');
49
1808c2da 50is($bar->foo(), 'Foo::foo', 'got the right value from &foo');
51is($bar->bar(), 'Bar::bar -> Foo::bar', 'got the right value from &bar');
52is($bar->baz(), 'Foo::baz', 'got the right value from &baz');
159da176 53
54my $foo = Foo->new();
55isa_ok($foo, 'Foo');
56
1808c2da 57is($foo->foo(), 'Foo::foo', 'got the right value from &foo');
58is($foo->bar(), 'Foo::bar', 'got the right value from &bar');
59is($foo->baz(), 'Foo::baz', 'got the right value from &baz');
d05cd563 60
61# some error cases
62
63{
64 package Bling;
d05cd563 65 use Moose;
d03bd989 66
d05cd563 67 sub bling { 'Bling::bling' }
d03bd989 68
d05cd563 69 package Bling::Bling;
d05cd563 70 use Moose;
d03bd989 71
d05cd563 72 extends 'Bling';
d03bd989 73
74 sub bling { 'Bling::bling' }
75
d05cd563 76 ::dies_ok {
77 override 'bling' => sub {};
1808c2da 78 } 'cannot override a method which has a local equivalent';
d03bd989 79
d05cd563 80}
81