14 sub foo { 'Foo::foo(' . (inner() || '') . ')' }
15 sub bar { 'Foo::bar(' . (inner() || '') . ')' }
16 sub baz { 'Foo::baz(' . (inner() || '') . ')' }
23 augment foo => sub { 'Bar::foo(' . (inner() || '') . ')' };
24 augment bar => sub { 'Bar::bar' };
26 no Moose; # ensure inner() still works after unimport
33 augment foo => sub { 'Baz::foo' };
34 augment baz => sub { 'Baz::baz' };
36 # this will actually never run,
37 # because Bar::bar does not call inner()
38 augment bar => sub { 'Baz::bar' };
46 is($baz->foo(), 'Foo::foo(Bar::foo(Baz::foo))', '... got the right value from &foo');
47 is($baz->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar');
48 is($baz->baz(), 'Foo::baz(Baz::baz)', '... got the right value from &baz');
54 is($bar->foo(), 'Foo::foo(Bar::foo())', '... got the right value from &foo');
55 is($bar->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar');
56 is($bar->baz(), 'Foo::baz()', '... got the right value from &baz');
61 is($foo->foo(), 'Foo::foo()', '... got the right value from &foo');
62 is($foo->bar(), 'Foo::bar()', '... got the right value from &bar');
63 is($foo->baz(), 'Foo::baz()', '... got the right value from &baz');
65 # test saved state when crossing objects
70 has name => (is => 'rw');
72 "$_[0]->{name}.X", inner()
78 augment 'run' => sub {
79 "$_[0]->{name}.Y", ($_[1] ? $_[1]->() : ()), inner();
85 augment 'run' => sub {
90 is('a.X a.Y b.X b.Y b.Z a.Z',
92 my $a = Z->new(name => 'a');
93 my $b = Z->new(name => 'b');
94 join(' ', $a->run(sub { $b->run }))
96 'State is saved when cross-calling augmented methods on different objects');
104 sub bling { 'Bling::bling' }
106 package Bling::Bling;
111 sub bling { 'Bling::bling' }
113 ::isnt( ::exception {
114 augment 'bling' => sub {};
115 }, undef, '... cannot augment a method which has a local equivalent' );