Cannot accept an arrayref to pos_validated_list, since this can be confused with...
[gitmo/MooseX-Params-Validate.git] / t / 012_ref_as_first_param.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Fatal;
8
9 {
10     use MooseX::Params::Validate;
11
12     sub foo {
13         my ( $x, $y ) = validated_list(
14             \@_,
15             x => { isa => 'Any' },
16             y => { isa => 'Any' },
17         );
18
19         return { x => $x, y => $y };
20     }
21
22     sub bar {
23         my %p = validated_hash(
24             \@_,
25             x => { isa => 'Any' },
26             y => { isa => 'Any' },
27         );
28
29         return \%p;
30     }
31 }
32
33 is_deeply(
34     foo( x => 42, y => 84 ),
35     { x => 42, y => 84 },
36     'validated_list accepts a plain hash'
37 );
38
39 is_deeply(
40     foo( { x => 42, y => 84 } ),
41     { x => 42, y => 84 },
42     'validated_list accepts a hash reference'
43 );
44
45 is_deeply(
46     bar( x => 42, y => 84 ),
47     { x => 42, y => 84 },
48     'validated_hash accepts a plain hash'
49 );
50
51 is_deeply(
52     bar( { x => 42, y => 84 } ),
53     { x => 42, y => 84 },
54     'validated_hash accepts a hash reference'
55 );
56
57 done_testing();