in reply to Re^4: Distinguish between missing and undefined arguments with subroutine signatures
in thread Distinguish between missing and undefined arguments with subroutine signatures
Trying to implement it according to your remarks leads me to something I don't like at all.
EDIT: See comments in uglier_foo.
my $missing = sub {...}; # private sub sub ugly_foo ($self, $foo=$missing->(), $bar=$missing->()) { say "foo is missing" if $missing->($foo); say "bar is missing" if $missing->($bar); } # compare with eq sub uglier_foo($self, $foo=MISSING, $bar=MISSING) { # This comes from posting insufficiently tested code at midnight # say "foo is missing" if !$foo || $foo eq MISSING; # say "bar is missing" if !$foo || $foo eq MISSING; say "foo is missing" if $foo && $foo eq MISSING; say "bar is missing" if $bar && $bar eq MISSING; } # slurping sub ugliest_foo ($self, @args) { my ($foo, $foo_missing); if (@args) { $foo = shift @args; } else { $foo_missing = 1; } my ($bar, $bar_missing); if (@args) { $bar = shift @args; } else { $bar_missing = 1; } if (@args) { croak "too many arguments"; } say "foo is missing" if $foo_missing; say "bar is missing" if $bar_missing; }
So, yes, I stubbornly stick to my solution.
Greetings,
-jo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Distinguish between missing and undefined arguments with subroutine signatures
by LanX (Saint) on Jan 08, 2021 at 23:02 UTC |