in reply to Distinguish between missing and undefined arguments with subroutine signatures
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Distinguish between missing and undefined arguments with subroutine signatures
by LanX (Saint) on Jan 08, 2021 at 19:59 UTC | |
by jo37 (Curate) on Jan 08, 2021 at 21:46 UTC | |
by LanX (Saint) on Jan 08, 2021 at 22:03 UTC | |
by jo37 (Curate) on Jan 08, 2021 at 22:58 UTC | |
by LanX (Saint) on Jan 08, 2021 at 23:02 UTC |