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