summaryrefslogtreecommitdiffstats
path: root/t/004-generate-method.t
blob: 999fd1e93ca8491424928df9c427a67c170d2bbd (plain) (blame)
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 4;
use Test::Moose;

BEGIN {
    package Foo::Exporter;
    use MooseX::MethodTraits;

    MooseX::MethodTraits->setup_import_methods(
        with_traits => {
            alias => {
                traits => ['Foo::Alias'],
                munge  => sub {
                    my $name = shift;
                    return sub { shift->$name(@_) },
                           [ aliased_from => $name, @_ ];
                },
            }
        }
    );
}

{
    package Foo::Alias;
    use Moose::Role;

    has aliased_from => (
        is  => 'ro',
        isa => 'Str',
    );
}

{
    package Foo;
    use Moose;
    BEGIN { Foo::Exporter->import }

    sub foo { 'FOO' }
    alias bar => 'foo';
}

my $foo = Foo->new;
can_ok($foo, 'bar');
my $method = Foo->meta->get_method('bar');
does_ok($method, 'Foo::Alias');
is($method->aliased_from, 'foo', 'method knows where it came from');
is($foo->bar, 'FOO', 'aliased properly');