Add MX_PARAMS_VALIDATE_ALLOW_EXTRA
[gitmo/MooseX-Params-Validate.git] / t / 009_wrapped.t
CommitLineData
d9d1529d 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 2;
7use Test::Exception;
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 \@_,
18 foo => { isa => 'Str' },
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(
31 \@args,
32 bar => { isa => 'Str' },
33 );
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(
46 \@args,
47 quux => { isa => 'Str' },
48 );
49
50 $params{quux}, $self->$orig(%p);
51 };
52}
53
54{
55 my $foo = Foo->new;
56
57 is_deeply( [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ],
58 [ 3, 2, 1 ],
59 'multiple around wrappers can safely be cached' );
60
61 is_deeply( [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ],
62 [ 3, 2, 1 ],
63 'multiple around wrappers can safely be cached (2nd time)' );
64}
65