Subject: | Overload perl booleans at import time |
Would be nice if boolean provided an import time option to overload perl's booleans to be blessed into booleans, like this:
Show quoted text
&Internals::SvREADONLY( \ !!1, 0);
Show quoted text
${ \ !!1 } = boolean::true;
Show quoted text
&Internals::SvREADONLY( \ !!1, 1);
After this the following prints "boolean boolean 1 0":
print( ref(1 == 0), ' ', ref(1 == 1), ' ', (1 == 1), ' ', (0 == 1), "\n");
Show quoted text
# enable modifying true and false
&Internals::SvREADONLY( \ !!0, 0);&Internals::SvREADONLY( \ !!1, 0);
Show quoted text
# turn booleans into blessed booleans:
${ \ !!0 } = boolean::false;${ \ !!1 } = boolean::true;
Show quoted text
# make true and false read-only again
&Internals::SvREADONLY( \ !!0, 1);&Internals::SvREADONLY( \ !!1, 1);
After this the following prints "boolean boolean 1 0":
print( ref(1 == 0), ' ', ref(1 == 1), ' ', (1 == 1), ' ', (0 == 1), "\n");