3 # Test the $arg = undef optional syntax.
6 use warnings FATAL => 'all';
15 use Function::Parameters qw(:strict);
17 method whatever($this = undef) {
21 is( Stuff->whatever(23), 23 );
23 method things($this = 99) {
27 is( Stuff->things(), 99 );
29 method some_optional($that, $this = undef) {
30 return $that + ($this || 0);
33 is( Stuff->some_optional(18, 22), 18 + 22 );
34 is( Stuff->some_optional(18), 18 );
37 # # are named parameters optional by default?
38 # method named_params(:$this, :$that) {}
40 # lives_ok { Stuff->named_params(this => 0) } 'can leave out some named params';
41 # lives_ok { Stuff->named_params( ) } 'can leave out all named params';
44 # are slurpy parameters optional by default?
45 # (throwing in a default just for a little feature interaction test)
46 method slurpy_param($this, $that = 0, @other) {}
49 is exception { Stuff->slurpy_param(0, 0, @a) }, undef, 'can pass empty array to slurpy param';
50 is exception { Stuff->slurpy_param(0, 0 ) }, undef, 'can omit slurpy param altogether';
51 is exception { Stuff->slurpy_param(0 ) }, undef, 'can omit other optional params as well as slurpy param';