Commit | Line | Data |
d9d1529d |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
d7a80104 |
6 | use Test::More; |
37088308 |
7 | use Test::Fatal; |
d9d1529d |
8 | |
9 | { |
10 | package Foo; |
11 | use Moose; |
12 | use MooseX::Params::Validate; |
13 | |
14 | sub foo { |
15 | my $self = shift; |
16 | my %params = validated_hash( |
17 | \@_, |
37088308 |
18 | foo => { isa => 'Str' }, |
d9d1529d |
19 | ); |
20 | return $params{foo}; |
21 | } |
22 | |
23 | around 'foo' => sub { |
24 | my $orig = shift; |
25 | my $self = shift; |
26 | my %p = @_; |
27 | |
28 | my @args = ( bar => delete $p{bar} ); |
29 | |
30 | my %params = validated_hash( |
37088308 |
31 | \@args, |
32 | bar => { isa => 'Str' }, |
33 | ); |
d9d1529d |
34 | |
35 | $params{bar}, $self->$orig(%p); |
36 | }; |
37 | |
38 | around 'foo' => sub { |
39 | my $orig = shift; |
40 | my $self = shift; |
41 | my %p = @_; |
42 | |
43 | my @args = ( quux => delete $p{quux} ); |
44 | |
45 | my %params = validated_hash( |
37088308 |
46 | \@args, |
47 | quux => { isa => 'Str' }, |
48 | ); |
d9d1529d |
49 | |
50 | $params{quux}, $self->$orig(%p); |
51 | }; |
52 | } |
53 | |
54 | { |
55 | my $foo = Foo->new; |
56 | |
37088308 |
57 | is_deeply( |
58 | [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ], |
59 | [ 3, 2, 1 ], |
60 | 'multiple around wrappers can safely be cached' |
61 | ); |
62 | |
63 | is_deeply( |
64 | [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ], |
65 | [ 3, 2, 1 ], |
66 | 'multiple around wrappers can safely be cached (2nd time)' |
67 | ); |
d9d1529d |
68 | } |
69 | |
d7a80104 |
70 | done_testing(); |