File: 005_override_augment_inner_super.t

package info (click to toggle)
libmoose-perl 1.09-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,004 kB
  • ctags: 1,472
  • sloc: perl: 25,387; makefile: 2
file content (71 lines) | stat: -rw-r--r-- 1,532 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;


{
    package Foo;
    use Moose;

    sub foo { 'Foo::foo(' . (inner() || '') . ')' };
    sub bar { 'Foo::bar(' . (inner() || '') . ')' }

    package Bar;
    use Moose;

    extends 'Foo';

    augment  'foo' => sub { 'Bar::foo' };
    override 'bar' => sub { 'Bar::bar -> ' . super() };

    package Baz;
    use Moose;

    extends 'Bar';

    override 'foo' => sub { 'Baz::foo -> ' . super() };
    augment  'bar' => sub { 'Baz::bar' };
}

my $baz = Baz->new();
isa_ok($baz, 'Baz');
isa_ok($baz, 'Bar');
isa_ok($baz, 'Foo');

=pod

Let em clarify what is happening here. Baz::foo is calling
super(), which calls Bar::foo, which is an augmented sub
that calls Foo::foo, then calls inner() which actually
then calls Bar::foo. Confusing I know,.. but this is
*exactly* what is it supposed to do :)

=cut

is($baz->foo,
  'Baz::foo -> Foo::foo(Bar::foo)',
  '... got the right value from mixed augment/override foo');

=pod

Allow me to clarify this one now ...

Since Baz::bar is an augment routine, it needs to find the
correct inner() to be called by. In this case it is Foo::bar.
However, Bar::bar is in-between us, so it should actually be
called first. Bar::bar is an overriden sub, and calls super()
which in turn then calls our Foo::bar, which calls inner(),
which calls Baz::bar.

Confusing I know, but it is correct :)

=cut

is($baz->bar,
    'Bar::bar -> Foo::bar(Baz::bar)',
    '... got the right value from mixed augment/override bar');

done_testing;