NAME
Locale::Unicode::Data::Boolean - Boolean Representation Class
SYNOPSIS
my $bool = Locale::Unicode::Data::Boolean->true;
# or
my $bool = Locale::Unicode::Data::Boolean::true;
# Now I have a Locale::Unicode::Data::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",
active: true
}
VERSION
v0.1.0
DESCRIPTION
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.
CONSTRUCTOR
new
Provided with a true, or false value, and this instantiate a new Locale::Unicode::Data::Boolean
object and returns it.
METHODS
clone
Returns a new object with the boolean value of the current object.
true
This returns a perl true value i.e. 1 or true
when added into JSON
false
This returns a perl false value i.e. 0 or false
when added into JSON
is_bool
Provided with a value and this returns true if it is a Locale::Unicode::Data::Boolean object
is_true
Provided with a value and this returns true if it is a Locale::Unicode::Data::Boolean object and this is true.
is_false
Provided with a value and this returns true if it is a Locale::Unicode::Data::Boolean object and this is false.
TO_JSON
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
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
AUTHOR
Jacques Deguest <jack@deguest.jp>
COPYRIGHT & LICENSE
Copyright (c) 2024 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.