schwern/method-signatures — Issue #45: modifiers for defaults (||=, //= and ''=)
Author: ruz
Created: 2011-12-28 17:07:18+00:00
State: open

Hi,

I've implemented subj. Didn't expect it to be so easy. Only a few tests and no docs. Will accept this new feature for inclusion? Example from tests:

# Test that undef, 0 and '' override defaults
method echo($message = 'what?') { return $message }
is( Stuff->echo(), 'what?' );
is( Stuff->echo(undef), undef );
is( Stuff->echo(''), '' );
is( Stuff->echo(0), 0 );
is( Stuff->echo('who?'), 'who?' );

# Test defaults modifiers
method echo_or ($message ||= 'what?') { return $message }
is( Stuff->echo_or(), 'what?' );
is( Stuff->echo_or(undef), 'what?' );
is( Stuff->echo_or(''), 'what?' );
is( Stuff->echo_or(0), 'what?' );
is( Stuff->echo_or('who?'), 'who?' );

method echo_dor($message //= 'what?') { return $message }
is( Stuff->echo_dor(), 'what?' );
is( Stuff->echo_dor(undef), 'what?' );
is( Stuff->echo_dor(''), '' );
is( Stuff->echo_dor(0), 0 );
is( Stuff->echo_dor('who?'), 'who?' );

method echo_eor($message ''= 'what?') { return $message }
is( Stuff->echo_eor(), 'what?' );
is( Stuff->echo_eor(undef), 'what?' );
is( Stuff->echo_eor(''), 'what?' );
is( Stuff->echo_eor(0), 0 );
is( Stuff->echo_eor('who?'), 'who?' );