File: 403-method-modifiers.t

package info (click to toggle)
libmouse-perl 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,156 kB
  • sloc: perl: 14,569; ansic: 218; makefile: 8
file content (59 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 4;
use Test::Exception;

my @calls;
my ($before, $after, $around);

do {
    package Role;
    use Mouse::Role;

    $before = sub {
        push @calls, 'Role::foo:before';
    };
    before foo => $before;

    $after = sub {
        push @calls, 'Role::foo:after';
    };
    after foo => $after;

    $around = sub {
        my $orig = shift;
        push @calls, 'Role::foo:around_before';
        $orig->(@_);
        push @calls, 'Role::foo:around_after';
    };
    around foo => $around;

    no Mouse::Role;
};

is_deeply([Role->meta->get_before_method_modifiers('foo')], [$before]);
is_deeply([Role->meta->get_after_method_modifiers('foo')],  [$after]);
is_deeply([Role->meta->get_around_method_modifiers('foo')], [$around]);

do {
    package Class;
    use Mouse;
    with 'Role';

    sub foo {
        push @calls, 'Class::foo';
    }

    no Mouse;
};

Class->foo;
is_deeply([splice @calls], [
    'Role::foo:before',
    'Role::foo:around_before',
    'Class::foo',
    'Role::foo:around_after',
    'Role::foo:after',
]);