summaryrefslogtreecommitdiff
path: root/t/bugs/traits_with_exporter.t
blob: 8f4fe92ab9b044cf94378bbf21f15930e7a0b331 (plain)
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
use strict;
use warnings;

use Test::More;
use lib 't/lib';

BEGIN {
    package MyExporterRole;

    use Moose ();
    use Moose::Exporter;

    Moose::Exporter->setup_import_methods(
        also      => 'Moose',
    );

    sub init_meta {
        my ($class,%args) = @_;

        my $meta = Moose->init_meta( %args );

        Moose::Util::MetaRole::apply_metaroles(
            for             => $meta,
            class_metaroles => {
                class           => ['MyMetaRole'],
            },
        );

        return $meta;
    }

    $INC{'MyExporterRole.pm'} = __FILE__;
}

{
    package MyMetaRole;
    use Moose::Role;

    sub some_meta_class_method {
        return "HEY"
    }
}

{
    package MyTrait;
    use Moose::Role;

    sub some_meta_class_method_defined_by_trait {
        return "HO"
    }

    {
        package Moose::Meta::Class::Custom::Trait::MyClassTrait;
        use strict;
        use warnings;
        sub register_implementation { return 'MyTrait' }
    }
}

{
    package MyClass;
    use MyExporterRole -traits => 'MyClassTrait';
}



my $my_class = MyClass->new;

isa_ok($my_class,'MyClass');

my $meta = $my_class->meta();
# Check if MyMetaRole has been applied
ok($meta->can('some_meta_class_method'),'Meta class has some_meta_class_method');
# Check if MyTrait has been applied
ok($meta->can('some_meta_class_method_defined_by_trait'),'Meta class has some_meta_class_method_defined_by_trait');

done_testing;