from my experience are mutators written in a way to always return the value.
> A call with an undefined arg clears the attribute - just like in my example.
OK ... but in that case why do you have a default value at all?
Anyway, if you want to allow to set to undef and don't wanna introspect @_ , then you're stuck in a kind of semipredicate problem.
Such problems can be solved in Perl by setting a new "impossible"° object MISSING as default, like
use constant MISSING => bless {}, "MyPackg::__Missing__"
and later
sub mutator ($value = MISSING) { ...BODY... }
(untested)
If you see that an arguments equals to that "impossible" value blessed into your own private namespace below "MyPackg", you can be sure that it wasn't used by accident.
HTH! :)
clearer rewording, clearer code
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
°) of course it's possible that such a value is used, but extremely unlikely without intend.
In reply to Re^3: Distinguish between missing and undefined arguments with subroutine signatures (semipredicate problem)
by LanX
in thread Distinguish between missing and undefined arguments with subroutine signatures
by jo37
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |