File: role_comp.t

package info (click to toggle)
libmoosex-methodattributes-perl 0.32-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 496 kB
  • sloc: perl: 648; makefile: 2
file content (83 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
use strict;
use warnings;
use Test::More 0.88;
use Test::Fatal;

use Moose::Util qw/apply_all_roles/;

{
    package BaseClass;
    use Moose;
    use MooseX::MethodAttributes;
    no Moose;
}

{
    package AClass;
    use Moose;
    BEGIN { extends 'BaseClass' }
    sub foo : Bar {}

    no Moose;
}

{
    package Role1;
    use Moose::Role;
    our $called = 0;
    sub pack { $called++ }
    no Moose::Role;
}

{
    package Role2;
    use Moose::Role;

    our $called = 0;
    around pack => sub {
        my ($orig, $self, @rest) = @_;
        $called++;
        $self->$orig(@rest);
    };
    no Moose::Role;
}

{
    package BClass;
    use Moose;
    BEGIN { extends 'AClass' };

    sub moo : Quux {}

    ::is ::exception { with qw/Role1 Role2/ }, undef;
    no Moose;
}

{
    package CClass;
    use Moose;
    BEGIN { extends 'AClass' };

    sub moo : Quux {}
    no Moose;
}

my $c = CClass->new;
is exception { apply_all_roles($c, qw/Role1 Role2/) }, undef;

foreach my $i (BClass->new, $c) {
    $Role1::called = $Role2::called = 0;
    can_ok $i, 'pack' and $i->pack;
    is $Role1::called, 1;
    is $Role2::called, 1;
    is_deeply(
        $i->meta->find_method_by_name('foo')->attributes,
        [(q{Bar})],
    );
    is_deeply(
        $i->meta->find_method_by_name('moo')->attributes,
        [(q{Quux})],
    );
}

done_testing;