1#!/usr/bin/perl -w 2 3# Test the $arg? optional syntax. 4 5use strict; 6use warnings; 7 8use Test::More; 9 10{ 11 package Stuff; 12 13 use Test::More; 14 use Test::Exception; 15 use Method::Signatures; 16 17 method whatever($this?) { 18 return $this; 19 } 20 21 is( Stuff->whatever(23), 23 ); 22 23 method things($this? = 99) { 24 return $this; 25 } 26 27 is( Stuff->things(), 99 ); 28 29 method some_optional($that, $this?) { 30 return $that + ($this || 0); 31 } 32 33 is( Stuff->some_optional(18, 22), 18 + 22 ); 34 is( Stuff->some_optional(18), 18 ); 35 36 37 # are named parameters optional by default? 38 method named_params(:$this, :$that) {} 39 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'; 42 43 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) {} 47 48 my @a = (); 49 lives_ok { Stuff->slurpy_param(0, 0, @a) } 'can pass empty array to slurpy param'; 50 lives_ok { Stuff->slurpy_param(0, 0 ) } 'can omit slurpy param altogether'; 51 lives_ok { Stuff->slurpy_param(0 ) } 'can omit other optional params as well as slurpy param'; 52} 53 54 55done_testing; 56