--- Types-Serialiser/Serialiser.pm 2013/11/30 18:33:51 1.9 +++ Types-Serialiser/Serialiser.pm 2020/12/01 01:47:20 1.10 @@ -19,7 +19,7 @@ use common::sense; # required to suppress annoying warnings -our $VERSION = '1.0'; +our $VERSION = '1.01'; =head1 SIMPLE SCALAR CONSTANTS @@ -28,6 +28,9 @@ scalars. This is necessary because these have different representations in the serialisation formats. +In the following, functions with zero or one arguments have a prototype of +C<()> and C<($)>, respectively, so act as constants and unary operators. + =head2 BOOLEANS (Types::Serialiser::Boolean class) This type has only two instances, true and false. A natural representation @@ -54,6 +57,13 @@ The constant is represented as a reference to a scalar containing C<0> - implementations are allowed to directly test for this. +=item Types::Serialiser::as_bool $value + +Converts a Perl scalar into a boolean, which is useful syntactic +sugar. Strictly equivalent to: + + $value ? $Types::Serialiser::true : $Types::Serialiser::false + =item $is_bool = Types::Serialiser::is_bool $value Returns true iff the C<$value> is either C<$Types::Serialiser::true> or @@ -129,6 +139,8 @@ sub false () { $false } sub error () { $error } +sub as_bool($) { $_[0] ? $true : $false } + sub is_bool ($) { UNIVERSAL::isa $_[0], Types::Serialiser::Boolean:: } sub is_true ($) { $_[0] && UNIVERSAL::isa $_[0], Types::Serialiser::Boolean:: } sub is_false ($) { !$_[0] && UNIVERSAL::isa $_[0], Types::Serialiser::Boolean:: }