summaryrefslogtreecommitdiff
path: root/t/metaclasses/exporter_meta_lookup.t
blob: 629b48b9f036aaf1bcb4bab49a740113769fad9d (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
use strict;
use warnings;

use Test::More;

{
    package Class::Vacuum::Innards;
    use Moose;

    package Class::Vacuum;
    use Moose ();
    use Moose::Exporter;

    sub meta_lookup { $_[0] }

    BEGIN {
        Moose::Exporter->setup_import_methods(
            also        => 'Moose',
            meta_lookup => sub { Class::MOP::class_of('Class::Vacuum::Innards') },
            with_meta   => ['meta_lookup'],
        );
    }
}

{
    package Victim;
    BEGIN { Class::Vacuum->import };

    has star_rod => (
        is => 'ro',
    );

    ::is(meta_lookup, Class::Vacuum::Innards->meta, "right meta_lookup");
}

ok(Class::Vacuum::Innards->can('star_rod'), 'Vacuum stole the star_rod method');
ok(!Victim->can('star_rod'), 'Victim does not get it at all');

{
    package Class::Vacuum::Reexport;
    use Moose::Exporter;

    BEGIN {
        Moose::Exporter->setup_import_methods(also => 'Class::Vacuum');
    }
}

{
    package Victim2;
    BEGIN { Class::Vacuum::Reexport->import }

    has parasol => (
        is => 'ro',
    );

    ::is(meta_lookup, Class::Vacuum::Innards->meta, "right meta_lookup");
}

ok(Class::Vacuum::Innards->can('parasol'), 'Vacuum stole the parasol method');
ok(!Victim2->can('parasol'), 'Victim does not get it at all');

done_testing;