summaryrefslogtreecommitdiffstats
path: root/t/010-mangle-args.t
blob: 1f07ca7d699b9cbf1390e8c367635223a7eec7d5 (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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 4;

package Foo;
use Moose;

sub foo {
    shift;
    return reverse @_;
}

sub bar {
    shift;
    return join '-', @_
}

package Foo::Sub;
use Moose;
use MooseX::Mangle;
extends 'Foo';

mangle_args foo => sub {
    shift;
    return map { uc } @_;
};

mangle_args bar => sub {
    my $self = shift;
    pop;
    return @_;
};

package main;
my $foo = Foo->new;
my $foosub = Foo::Sub->new;
is_deeply([$foo->foo(qw(a b c))], [qw(c b a)], 'unmodified method foo');
is($foo->bar(qw(a b c)), 'a-b-c', 'unmodified method bar');
is_deeply([$foosub->foo(qw(a b c))], [qw(C B A)], "foo's args are mangled");
is($foosub->bar(qw(a b c)), 'a-b', "bar's args are mangled");