Commit | Line | Data |
1a52f2db |
1 | #!perl |
2 | use strict; |
3 | use warnings FATAL => 'all'; |
4 | use Test::More |
5 | eval { |
6 | require Moose; |
7 | require Test::Deep; |
8 | } |
9 | ? (tests => 4) |
10 | : (skip_all => "Moose, Test::Deep required for testing types") |
11 | ; |
12 | |
13 | # assigned to by each 'foo' method |
14 | my $captured_args; |
15 | |
16 | { |
17 | package Named; |
18 | |
19 | use Moose; |
20 | use Function::Parameters qw(:strict); |
21 | |
22 | # use Data::Dumper; |
23 | |
24 | method foo ( |
25 | Str :$foo_a, |
26 | Maybe[Str] :$foo_b = undef) { |
27 | $captured_args = \@_; |
28 | } |
29 | } |
30 | |
31 | |
32 | { |
33 | package Positional; |
34 | use Moose; |
35 | use Function::Parameters qw(:strict); |
36 | |
37 | # use Data::Dumper; |
38 | |
39 | method foo ( |
40 | Str $foo_a, |
41 | Maybe[Str] $foo_b = undef) { |
42 | $captured_args = \@_; |
43 | } |
44 | } |
45 | |
46 | |
47 | use Test::Deep; |
48 | #use Data::Dumper; |
49 | |
50 | |
51 | |
52 | my $positional = Positional->new; |
53 | $positional->foo('str', undef); |
54 | |
55 | cmp_deeply( |
56 | $captured_args, |
57 | [ |
58 | #noclass({}), |
59 | 'str', |
60 | undef, |
61 | ], |
62 | 'positional: explicit undef shows up in @_ correctly', |
63 | ); |
64 | |
65 | $positional->foo('str'); |
66 | |
67 | cmp_deeply( |
68 | $captured_args, |
69 | [ |
70 | #noclass({}), |
71 | 'str', |
72 | ], |
73 | 'positional: omitting an argument results in no entry in @_', |
74 | ); |
75 | |
76 | my $named = Named->new; |
77 | $named->foo(foo_a => 'str', foo_b => undef); |
78 | |
79 | cmp_deeply( |
80 | $captured_args, |
81 | [ |
82 | #noclass({}), |
83 | foo_a => 'str', |
84 | foo_b => undef, |
85 | ], |
86 | 'named: explicit undef shows up in @_ correctly', |
87 | ); |
88 | |
89 | $named->foo(foo_a => 'str'); |
90 | |
91 | #TODO: { |
92 | # local $TODO = 'this fails... should work the same as for positional args.'; |
93 | cmp_deeply( |
94 | $captured_args, |
95 | [ |
96 | #noclass({}), |
97 | foo_a => 'str', |
98 | ], |
99 | 'named: omitting an argument results in no entry in @_', |
100 | ); |
101 | |
102 | #print "### named captured args: ", Dumper($captured_args); |
103 | #} |
104 | |
105 | |
106 | |
107 | |