Using LanX's suggestion in Re^3: Distinguish between missing and undefined arguments with subroutine signatures (semipredicate problem), I finally found a practicable solution to my problem.
# Unique catcher for a missing argument use constant MISSING => bless {}, __PACKAGE__ . '::__missing__'; # Helper sub, that either checks its argument against the catcher # or otherwise returns the catcher itself. sub missing { @_ ? $_[0] && $_[0] eq MISSING : MISSING; } # To be used with signatures in various places: sub foo ($self, $val=missing) { if (missing $val) { # getter } else { # setter } }
Thanks, Rolf!
Greetings,
-jo
In reply to Re: Distinguish between missing and undefined arguments with subroutine signatures
by jo37
in thread Distinguish between missing and undefined arguments with subroutine signatures
by jo37
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |