Module::Generic::Boolean - Boolean Representation Class
my $bool = Module::Generic::Boolean->true;
my $bool = Module::Generic::Boolean::true;
# Now I have a Module::Generic::Boolean object
# Returns 1
if( $bool )
# Do something
my $hash =
name => 'John Doe',
active => $bool,
# Converting to json
print( JSON->new->encode( $hash ), "\n" );
# Would result in
name: "Jogn Doe",
This a class/package to represent boolean value and make sure they are recognised interchangeably as perl boolean, i.e. 1 or 0, or as JSON bool, i.e. true or false
The code is taken and adapted from part of JSON module.
Returns an Module::Generic::Array object with the current boolean value as its only entry.
my $true = Module::Generic::Boolean->true;
my $a = $true->as_array;
say $a->; # 1
Returns the current boolean value (1 or 0) as a Module::Generic::Number object.
Returns the current boolean value (1 or 0) as a Module::Generic::Scalar object.
This returns a perl true value i.e. 1 or true when added into JSON
This returns a perl false value i.e. 0 or false when added into JSON
Provided with a value and this returns true if it is a Module::Generic::Boolean object
Provided with a value and this returns true if it is a Module::Generic::Boolean object and this is true.
Provided with a value and this returns true if it is a Module::Generic::Boolean object and this is false.
This is called by JSON to transform an object into json data format.
It returns \1 if true, or \0 otherwise. Those values are understood by JSON and transcoded accordingly.
Serialisation by CBOR, Sereal and Storable::Improved (or the legacy Storable) is supported by this package. To that effect, the following subroutines are implemented: FREEZE, THAW, STORABLE_freeze and STORABLE_thaw
Jacques Deguest <email@example.com>
Copyright (c) 2000-2020 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
To install Module::Generic, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.