view release on metacpan or search on metacpan
WebDriver.pm view on Meta::CPAN
our $WEB_FRAME_IDENTIFIER = "frame-075b-4da1-b6ba-e579c2d3230a";
my $json = eval { require JSON::XS; JSON::XS:: } || do { require JSON::PP; JSON::PP:: };
$json = $json->new->utf8;
$json->boolean_values (0, 1)
if $json->can ("boolean_values");
sub _decode_base64 {
require MIME::Base64;
MIME::Base64::decode_base64 (shift)
view all matches for this distribution
view release on metacpan or search on metacpan
lib/ChordPro/Config/Data.pm view on Meta::CPAN
# Config version.
our $VERSION = 6.081;
sub config {
state $pp = JSON::XS->new->utf8
->boolean_values( $JSON::Boolean::false, $JSON::Boolean::true );
$pp->decode( <<'EndOfJSON' );
{"a2crd":{"classifier":"pct_chords","infer-titles":true,"tabstop":"8"},"assets":{},"chord-formats":{"common":"%{root|%{}%{qual|%{}}%{ext|%{}}%{bass|/%{}}|%{name}}","nashville":"%{root|%{}%{qual|<sup>%{}</sup>}%{ext|<sup>%{}</sup>}%{bass|/<sub>%{}</su...
EndOfJSON
}
view all matches for this distribution
view release on metacpan or search on metacpan
script/platform-info view on Meta::CPAN
#}
#
#
#sub get_max_size { $_[0]->{max_size}; }
#
#sub boolean_values {
# my $self = shift;
# if (@_) {
# my ($false, $true) = @_;
# $self->{false} = $false;
# $self->{true} = $true;
script/platform-info view on Meta::CPAN
# delete $self->{true};
# return;
# }
#}
#
#sub get_boolean_values {
# my $self = shift;
# if (exists $self->{true} and exists $self->{false}) {
# return @$self{qw/false true/};
# }
# return;
view all matches for this distribution
view release on metacpan or search on metacpan
inc/bundle/JSON/PP.pm view on Meta::CPAN
}
sub get_max_size { $_[0]->{max_size}; }
sub boolean_values {
my $self = shift;
if (@_) {
my ($false, $true) = @_;
$self->{false} = $false;
$self->{true} = $true;
inc/bundle/JSON/PP.pm view on Meta::CPAN
sub get_unblessed_bool {
my $self = shift;
return $self->get_core_bools(@_);
}
sub get_boolean_values {
my $self = shift;
if (exists $self->{true} and exists $self->{false}) {
return @$self{qw/false true/};
}
return;
inc/bundle/JSON/PP.pm view on Meta::CPAN
If C<$enable> is false (the default), then C<encode> will not consider
this type of conversion, and tagged JSON values will cause a parse error
in C<decode>, as if tags were not part of the grammar.
=head2 boolean_values
$json->boolean_values([$false, $true])
($false, $true) = $json->get_boolean_values
By default, JSON booleans will be decoded as overloaded
C<$JSON::PP::false> and C<$JSON::PP::true> objects.
With this method you can specify your own boolean values for decoding -
inc/bundle/JSON/PP.pm view on Meta::CPAN
(and add a C<TO_JSON> method if necessary).
Calling this method without any arguments will reset the booleans
to their default values.
C<get_boolean_values> will return both C<$false> and C<$true> values, or
the empty list when they are set to the default.
=head2 core_bools
$json->core_bools([$enable]);
If C<$enable> is true (or missing), then C<decode>, will produce standard
perl boolean values. Equivalent to calling:
$json->boolean_values(!!1, !!0)
C<get_core_bools> will return true if this has been set. On perl 5.36, it will
also return true if the boolean values have been set to perl's core booleans
using the C<boolean_values> method.
The methods C<unblessed_bool> and C<get_unblessed_bool> are provided as aliases
for compatibility with L<Cpanel::JSON::XS>.
=head2 filter_json_object
view all matches for this distribution
view release on metacpan or search on metacpan
_Deparsed_XSubs.pm view on Meta::CPAN
sub allow_blessed;
sub allow_nonref;
sub allow_tags;
sub allow_unknown;
sub ascii;
sub boolean_values;
sub canonical;
sub convert_blessed;
sub decode;
sub decode_json($) ;
sub decode_prefix;
_Deparsed_XSubs.pm view on Meta::CPAN
sub get_allow_blessed;
sub get_allow_nonref;
sub get_allow_tags;
sub get_allow_unknown;
sub get_ascii;
sub get_boolean_values;
sub get_canonical;
sub get_convert_blessed;
sub get_indent;
sub get_latin1;
sub get_max_depth;
view all matches for this distribution
view release on metacpan or search on metacpan
t/002-scalar.t view on Meta::CPAN
use Test::More tests => 72;
use Data::Printer::Object;
use Scalar::Util;
test_basic_values();
test_boolean_values();
test_tainted_values();
test_unicode_string();
test_escape_chars();
test_print_escapes();
test_max_string();
t/002-scalar.t view on Meta::CPAN
$object = Data::Printer::Object->new( colored => 0 );
$var = 123;
is $object->parse(\$var), '123', 'integer 123 in variable';
}
sub test_boolean_values {
SKIP: {
skip 'booleans only exist after 5.36', 5 unless $] ge '5.036000';
my $object = Data::Printer::Object->new( colored => 0 );
my $var = 1 == 1;
is $object->parse(\$var), 'true', 'boolean true is "true"';
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Roundtrip.pm view on Meta::CPAN
if( ! defined $pv ){ print STDERR "yamlfile2perl() : error, call to yaml2perl() has failed after reading yaml string from file '${yaml_file}'.\n"; return undef }
return $pv;
}
# Optional input parameter following the required $json_string
# is a HASHREF:
# 'boolean_values' => [X, Y] : this is an ARRAYREF of 2 items json-false is mapped to X
# and json-true is mapped to Y, e.g. [0,1].
# JSON's default is JSON::PP::Boolean objects. Yikes
sub json2perl {
my $json_string = $_[0];
my $params = defined($_[1]) ? $_[1] : {};
my $pv;
# NOTE: the JSON OO interface has encode() and decode()
# whereas the function has encode_json() and decode_json()
if( _has_utf8($json_string) ){
if( exists($params->{'boolean_values'}) && defined($params->{'boolean_values'}) && ref($params->{'boolean_values'})eq'ARRAY' ){
# in OO it needs decode()
# boolean_values(x,y)
$pv = eval {
JSON->new()
->boolean_values(@{ $params->{'boolean_values'} })
->utf8(0)->decode($json_string)
};
} else {
# intercepting a die by wrapping in an eval
$pv = eval { JSON::decode_json(Encode::encode_utf8($json_string)) };
}
if( ! defined($pv) ){ print STDERR Devel::StackTrace->new->as_string . "\njson2perl() : error, call to json2perl() has failed".((defined($@)&&($@!~/^\s*$/))?" with this exception: $@:":".")."\n"; return undef }
} else {
if( exists($params->{'boolean_values'}) && defined($params->{'boolean_values'}) && ref($params->{'boolean_values'})eq'ARRAY' ){
# boolean_values(x,y)
$pv = eval {
JSON->new()
->boolean_values(@{ $params->{'boolean_values'} })
->decode($json_string)
};
} else {
# intercepting a damn die by wrapping it around an eval
$pv = eval { JSON::decode_json($json_string) };
lib/Data/Roundtrip.pm view on Meta::CPAN
json2json($jsonstr, {'escape-unicode'=>1});
# sometimes we want JSON's true and false values
# to be mapped to something other than JSON::PP::Boolean objects:
my $json_with_custom_boolean_mapping = json2perl($jsonstr,
{'boolean_values' => 'myfalse', 'mytrue'});
my $json_with_custom_boolean_mapping = json2perl($jsonstr,
{'boolean_values' => 0, 1});
# With version 0.18 and up two more exported-on-demand
# subs were added to read JSON or YAML directly from a file:
# jsonfile2perl() and yamlfile2perl()
my $perldata = jsonfile2perl("file.json");
lib/Data/Roundtrip.pm view on Meta::CPAN
=over 4
=item * C<$jsonstring>
=item * C<$optional_paramshashref> is an optional hashref as it is blindingly obvious from
the name. At the moment only one parameter is understood: C<boolean_values>.
It must be an ARRAYREF of 0 or 2 elements. If 0 elements, then it resets the boolean
values mapping of the JSON converter to its default state (which is L<JSON::PP::Boolean> objects.
If it contains 2 elements, then the JSON converter will map a JSON C<false> value to
the first element of the ARRAYREF and a JSON C<true> value to
the second element of the ARRAYREF.
view all matches for this distribution
view release on metacpan or search on metacpan
sub defjson($name, $canon, $text, $val) {
# Use similar options for fair comparisons.
my $cp = Cpanel::JSON::XS->new->allow_nonref->unblessed_bool->convert_blessed;
my $pp = JSON::PP->new->allow_nonref->core_bools->convert_blessed;
my $xs = JSON::XS->new->allow_nonref->boolean_values([false,true])->convert_blessed;
my $si = JSON::SIMD->new->allow_nonref->core_bools->convert_blessed;
my $c_cp = Cpanel::JSON::XS->new->allow_nonref->unblessed_bool->convert_blessed->canonical;
my $c_pp = JSON::PP->new->allow_nonref->core_bools->convert_blessed->canonical;
my $c_xs = JSON::XS->new->allow_nonref->boolean_values([false,true])->convert_blessed->canonical;
my $c_si = JSON::SIMD->new->allow_nonref->core_bools->convert_blessed->canonical;
my $enc = json_format $val;
def "json/$name", $text, [ 'Encode', $canon ? 'Canonical' : (), 'Decode' ],
[ 'JSON::PP', undef, sub { $pp->encode($val) }, $canon ? sub { $c_pp->encode($val) } : (), sub { $pp->decode($enc) } ],
[ 'JSON::Tiny', undef, sub { JSON::Tiny::to_json($val) }, $canon ? undef : (), sub { JSON::Tiny::from_json($enc) } ],
view all matches for this distribution
view release on metacpan or search on metacpan
lib/GDPR/IAB/TCFv2.pm view on Meta::CPAN
json => $opts{json} || {},
strict => $strict,
);
$options{json}->{date_format} ||= DATE_FORMAT_ISO_8601;
$options{json}->{boolean_values} ||= [ _json_false(), _json_true() ];
if ( exists $opts{prefetch} ) {
my $prefetch = $opts{prefetch};
$prefetch = [$prefetch] if ref($prefetch) ne ref( [] );
lib/GDPR/IAB/TCFv2.pm view on Meta::CPAN
}
sub TO_JSON {
my $self = shift;
my ( $false, $true ) = @{ $self->{options}->{json}->{boolean_values} };
my $created = $self->_format_date( $self->created );
my $last_updated = $self->_format_date( $self->last_updated );
return {
lib/GDPR/IAB/TCFv2.pm view on Meta::CPAN
'CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA.argAC0gAAAAAAAAAAAA',
json => {
verbose => 0,
compact => 1,
use_epoch => 0,
boolean_values => [ 0, 1 ],
date_format => '%Y%m%d', # yyymmdd
},
strict => 1,
prefetch => 284,
);
lib/GDPR/IAB/TCFv2.pm view on Meta::CPAN
L<ISO_8601|https://en.wikipedia.org/wiki/ISO_8601>. With C<use_epoch> we will return the unix epoch in seconds.
See L</TO_JSON> for more details.
=item *
C<boolean_values> if present, expects an arrayref if two elements: the C<false> and the C<true> values to be used in json encoding.
If omit, we will try to use C<JSON::false> and C<JSON::true> if the package L<JSON> is available, else we will fallback to C<0> and C<1>.
=item *
C<date_format> if present accepts two kinds of value: an C<string> (to be used on C<POSIX::strftime>) or a code reference to a subroutine that
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Google/ProtocolBuffers/Dynamic.pm view on Meta::CPAN
on Perls with 64-bit integers.
When enabled, values that don't fit in a 32-bit integer are returned as
L<Math::BigInt> objects.
=head2 boolean_values
Defaults to C<perl>.
It controls how boolean values are mapped in Perl. Accepted values are:
view all matches for this distribution
view release on metacpan or search on metacpan
lib/JSON/PP.pm view on Meta::CPAN
}
sub get_max_size { $_[0]->{max_size}; }
sub boolean_values {
my $self = shift;
if (@_) {
my ($false, $true) = @_;
$self->{false} = $false;
$self->{true} = $true;
lib/JSON/PP.pm view on Meta::CPAN
sub get_unblessed_bool {
my $self = shift;
return $self->get_core_bools(@_);
}
sub get_boolean_values {
my $self = shift;
if (exists $self->{true} and exists $self->{false}) {
return @$self{qw/false true/};
}
return;
lib/JSON/PP.pm view on Meta::CPAN
If C<$enable> is false (the default), then C<encode> will not consider
this type of conversion, and tagged JSON values will cause a parse error
in C<decode>, as if tags were not part of the grammar.
=head2 boolean_values
$json->boolean_values([$false, $true])
($false, $true) = $json->get_boolean_values
By default, JSON booleans will be decoded as overloaded
C<$JSON::PP::false> and C<$JSON::PP::true> objects.
With this method you can specify your own boolean values for decoding -
lib/JSON/PP.pm view on Meta::CPAN
(and add a C<TO_JSON> method if necessary).
Calling this method without any arguments will reset the booleans
to their default values.
C<get_boolean_values> will return both C<$false> and C<$true> values, or
the empty list when they are set to the default.
=head2 core_bools
$json->core_bools([$enable]);
If C<$enable> is true (or missing), then C<decode>, will produce standard
perl boolean values. Equivalent to calling:
$json->boolean_values(!!1, !!0)
C<get_core_bools> will return true if this has been set. On perl 5.36, it will
also return true if the boolean values have been set to perl's core booleans
using the C<boolean_values> method.
The methods C<unblessed_bool> and C<get_unblessed_bool> are provided as aliases
for compatibility with L<Cpanel::JSON::XS>.
=head2 filter_json_object
view all matches for this distribution
view release on metacpan or search on metacpan
scripts/rrjson.pl view on Meta::CPAN
print "\n" unless $pretty;
}
elsif ( $mode eq "json_xs" ) {
require JSON::XS;
print ( JSON::XS->new->canonical->utf8(0)->pretty($pretty)
->boolean_values( $JSON::PP::false, $JSON::PP::true )
->convert_blessed->encode($data) );
}
elsif ( $mode eq "toml" ) {
require TOML::Tiny;
scripts/rrjson.pl view on Meta::CPAN
}
else { # default JSON
require JSON::PP;
print ( JSON::PP->new->canonical->utf8(0)->pretty($pretty)
->boolean_values( $JSON::PP::false, $JSON::PP::true )
->convert_blessed->encode($data) );
}
}
################ Subroutines ################
view all matches for this distribution
view release on metacpan or search on metacpan
in C<decode>, as if tags were not part of the grammar.
This option is not compatible with C<use_simdjson>, and using this option
will silently disable simdjson mode.
=item $json->boolean_values ([$false, $true])
=item ($false, $true) = $json->get_boolean_values
By default, JSON booleans will be decoded as overloaded
C<$Types::Serialiser::false> and C<$Types::Serialiser::true> objects.
With this method you can specify your own boolean values for decoding -
assigning a value to another variable, i.e. C<$copy = $false>).
Calling this method without any arguments will reset the booleans
to their default values.
C<get_boolean_values> will return both C<$false> and C<$true> values, or
the empty list when they are set to the default.
=item $json->core_bools([$enable])
=item $enabled = $json->get_core_bools
If C<$enable> is true (or missing), then subsequent C<decode>s will produce
standard perl boolean values. Equivalent to calling:
$json->boolean_values(!!0, !!1)
C<get_core_bools> will return true if this has been set. On perl 5.36 or newer,
it will also return true if the boolean values have been set to perl's core
booleans using the boolean_values method.
If C<$enable> is false, the booleans are reset to their default values.
(See also C<encode_core_bools> for the encode counterpart of this.)
C<Types::Serialiser::false>, respectively. They are overloaded to act
almost exactly like the numbers C<1> and C<0>. You can check whether
a scalar is a JSON boolean by using the C<Types::Serialiser::is_bool>
function (after C<use Types::Serialier>, of course).
You can also use the C<boolean_values> method to supply your own true
and false values for decoding, or the C<core_bools> method to decode to
Perl's standard booleans (the special values !!0 or !!1, also available
as the aliases C<false> and C<true> from the (experimental) C<builtin>
module since perl 5.36).
view all matches for this distribution
view release on metacpan or search on metacpan
If C<$enable> is false (the default), then C<encode> will not consider
this type of conversion, and tagged JSON values will cause a parse error
in C<decode>, as if tags were not part of the grammar.
=item $json->boolean_values ([$false, $true])
=item ($false, $true) = $json->get_boolean_values
By default, JSON booleans will be decoded as overloaded
C<$Types::Serialiser::false> and C<$Types::Serialiser::true> objects.
With this method you can specify your own boolean values for decoding -
assigning a value to another variable, i.e. C<$copy = $false>).
Calling this method without any arguments will reset the booleans
to their default values.
C<get_boolean_values> will return both C<$false> and C<$true> values, or
the empty list when they are set to the default.
=item $json = $json->filter_json_object ([$coderef->($hashref)])
When C<$coderef> is specified, it will be called from C<decode> each
view all matches for this distribution
view release on metacpan or search on metacpan
lib/JSON.pm view on Meta::CPAN
If C<$enable> is false (the default), then C<encode> will not consider
this type of conversion, and tagged JSON values will cause a parse error
in C<decode>, as if tags were not part of the grammar.
=head2 boolean_values (since version 4.0)
$json->boolean_values([$false, $true])
($false, $true) = $json->get_boolean_values
By default, JSON booleans will be decoded as overloaded
C<$JSON::false> and C<$JSON::true> objects.
With this method you can specify your own boolean values for decoding -
lib/JSON.pm view on Meta::CPAN
(and add a C<TO_JSON> method if necessary).
Calling this method without any arguments will reset the booleans
to their default values.
C<get_boolean_values> will return both C<$false> and C<$true> values, or
the empty list when they are set to the default.
=head2 filter_json_object
$json = $json->filter_json_object([$coderef])
view all matches for this distribution
view release on metacpan or search on metacpan
lib/JSONLD.pm view on Meta::CPAN
use JSONLD;
my $infile = 'test.jsonld';
open(my $fh, '<', $infile) or die $!;
my $content = do { local($/); <$fh> };
my $data = JSON->new()->boolean_values(0, 1)->decode($content);
my $jld = JSONLD->new();
my $expanded = $jld->expand($data);
=head1 DESCRIPTION
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Module/Generic.pm view on Meta::CPAN
}
# NOTE: deserialise with JSON
elsif( $class eq 'JSON' )
{
my @options = qw(
allow_blessed allow_nonref allow_unknown allow_tags ascii boolean_values
canonical convert_blessed filter_json_object filter_json_single_key_object
indent latin1 max_depth max_size pretty relaxed space_after space_before utf8
);
my $json = JSON->new;
for( @options )
lib/Module/Generic.pm view on Meta::CPAN
}
# NOTE: serialise with JSON
elsif( $class eq 'JSON' )
{
my @options = qw(
allow_blessed allow_nonref allow_unknown allow_tags ascii boolean_values
canonical convert_blessed filter_json_object filter_json_single_key_object
indent latin1 max_depth max_size pretty relaxed space_after space_before utf8
);
my $json = JSON->new;
for( @options )
lib/Module/Generic.pm view on Meta::CPAN
=item * L<CBOR::Free>: C<canonical>, C<string_encode_mode>, C<preserve_references>, C<scalar_references>
=item * L<CBOR|CBOR::XS>: C<max_depth>, C<max_size>, C<allow_unknown>, C<allow_sharing>, C<allow_cycles>, C<forbid_objects>, C<pack_strings>, C<text_keys>, C<text_strings>, C<validate_utf8>, C<filter>
=item * L<JSON>: C<allow_blessed> C<allow_nonref> C<allow_unknown> C<allow_tags> C<ascii> C<boolean_values> C<canonical> C<convert_blessed> C<filter_json_object> C<filter_json_single_key_object> C<indent> C<latin1> C<max_depth> C<max_size> C<pretty> ...
=item * L<Sereal::Decoder/encode> if the serialiser is L<Sereal>: C<aliased_dedupe_strings>, C<canonical>, C<canonical_refs>, C<compress>, C<compress_level>, C<compress_threshold>, C<croak_on_bless>, C<dedupe_strings>, C<freeze_callbacks>, C<max_recu...
=item * L<Storable::Improved> / L<Storable>: no option available
view all matches for this distribution
view release on metacpan or search on metacpan
_Deparsed_XSubs.pm view on Meta::CPAN
sub allow_blessed;
sub allow_nonref;
sub allow_tags;
sub allow_unknown;
sub ascii;
sub boolean_values;
sub canonical;
sub convert_blessed;
sub decode;
sub decode_json($) ;
sub decode_prefix;
_Deparsed_XSubs.pm view on Meta::CPAN
sub get_allow_blessed;
sub get_allow_nonref;
sub get_allow_tags;
sub get_allow_unknown;
sub get_ascii;
sub get_boolean_values;
sub get_canonical;
sub get_convert_blessed;
sub get_indent;
sub get_latin1;
sub get_max_depth;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Neo4j/Types/ImplementorNotes.pod view on Meta::CPAN
=for comment Some of the Perl JSON modules are currently (2023) in the
process of adding support for core booleans. It may be
useful to wait until those implementations are completed
and then follow whichever approach they chose. See also:
L<JSON::PP/"boolean_values">,
L<rurban/Cpanel-JSON-XS#214|https://github.com/rurban/Cpanel-JSON-XS/issues/214>
=head2 Null
The Cypher C<null> value can be neatly implemented as Perl C<undef>.
view all matches for this distribution
view release on metacpan or search on metacpan
build/build_modules.pl view on Meta::CPAN
$all_methods->push( keys( %$core_methods ) );
}
my $sample_file = $base_dir->child( "$object.json" );
my $sample_data;
$sample_data = $sample_file->load_json( boolean_values => [\0, \1] ) if( $sample_file->exists );
my $synop = Module::Generic::Array->new;
if( defined( $sample_data ) )
{
my $args_string = &dump_this( $sample_data );
$synop->push( "my \$obj = ${base_class}::${module_name}->new( $args_string ) || die( ${base_class}::${module_name}->error );\n" );
view all matches for this distribution
view release on metacpan or search on metacpan
_Deparsed_XSubs.pm view on Meta::CPAN
sub allow_blessed;
sub allow_nonref;
sub allow_tags;
sub allow_unknown;
sub ascii;
sub boolean_values;
sub canonical;
sub convert_blessed;
sub decode;
sub decode_json($);
sub decode_prefix;
_Deparsed_XSubs.pm view on Meta::CPAN
sub get_allow_blessed;
sub get_allow_nonref;
sub get_allow_tags;
sub get_allow_unknown;
sub get_ascii;
sub get_boolean_values;
sub get_canonical;
sub get_convert_blessed;
sub get_indent;
sub get_latin1;
sub get_max_depth;
view all matches for this distribution
view release on metacpan or search on metacpan
scripts/RosettaCode/avl_tree.sf
scripts/RosettaCode/binary_digits.sf
scripts/RosettaCode/binary_search.sf
scripts/RosettaCode/binary_search_1.sf
scripts/RosettaCode/bitwise_operations.sf
scripts/RosettaCode/boolean_values.sf
scripts/RosettaCode/boolean_values_1.sf
scripts/RosettaCode/brace_expansion.sf
scripts/RosettaCode/brazilian_numbers.sf
scripts/RosettaCode/burrows_wheeler_transform.sf
scripts/RosettaCode/burrows_wheeler_transform_fast.sf
scripts/RosettaCode/cantor_set.sf
view all matches for this distribution
view release on metacpan or search on metacpan
lib/StorageDisplay/Collect.pm view on Meta::CPAN
# This package contains
# - two public subroutines
# - `use_pp_parser` to know if JSON:PP makes all the work alone
# - `decode_json` to decode a json text with the $json_parser object
# - a public `new` class method that returns
# - a plain JSON::PP object (if boolean_values method exists)
# - a __PACKAGE__ object (if not) that inherit from JSON::PP
# - an overrided `decode` method that
# - calls SUPER::decode
# - manually transforms JSON:::PP::Boolean into plain scalar
# $json_parser is
# - either a JSON::PP object (if boolean_values method exists)
# - or a StorageDisplay::Collect::JSON that inherit of JSON::PP
# but override the decode method
use base 'JSON::PP';
my $has_boolean_values;
sub new {
my $class = shift;
my $json_pp_parser;
if (!defined($has_boolean_values)) {
$json_pp_parser = JSON::PP->new;
$has_boolean_values = 0;
eval {
# workaround if not supported
$json_pp_parser->boolean_values(0, 1);
$has_boolean_values = 1;
};
}
my $parser;
if ($has_boolean_values) {
$parser = JSON::PP->new(@_);
$parser->boolean_values(0, 1);
} else {
$parser = JSON::PP::new(__PACKAGE__, @_);
}
eval {
# ignore if not supported
lib/StorageDisplay/Collect.pm view on Meta::CPAN
}
$json_parser->decode(@_);
}
sub pp_parser_has_boolean_values {
return $has_boolean_values;
}
sub jsonarray2perlhash {
my $json = shift;
my $root = shift;
view all matches for this distribution
view release on metacpan or search on metacpan
inc/JSON/PP.pm view on Meta::CPAN
}
sub get_max_size { $_[0]->{max_size}; }
sub boolean_values {
my $self = shift;
if (@_) {
my ($false, $true) = @_;
$self->{false} = $false;
$self->{true} = $true;
inc/JSON/PP.pm view on Meta::CPAN
delete $self->{true};
return;
}
}
sub get_boolean_values {
my $self = shift;
if (exists $self->{true} and exists $self->{false}) {
return @$self{qw/false true/};
}
return;
view all matches for this distribution
view release on metacpan or search on metacpan
cpan/JSON-PP/lib/JSON/PP.pm view on Meta::CPAN
}
sub get_max_size { $_[0]->{max_size}; }
sub boolean_values {
my $self = shift;
if (@_) {
my ($false, $true) = @_;
$self->{false} = $false;
$self->{true} = $true;
cpan/JSON-PP/lib/JSON/PP.pm view on Meta::CPAN
sub get_unblessed_bool {
my $self = shift;
return $self->get_core_bools(@_);
}
sub get_boolean_values {
my $self = shift;
if (exists $self->{true} and exists $self->{false}) {
return @$self{qw/false true/};
}
return;
cpan/JSON-PP/lib/JSON/PP.pm view on Meta::CPAN
If C<$enable> is false (the default), then C<encode> will not consider
this type of conversion, and tagged JSON values will cause a parse error
in C<decode>, as if tags were not part of the grammar.
=head2 boolean_values
$json->boolean_values([$false, $true])
($false, $true) = $json->get_boolean_values
By default, JSON booleans will be decoded as overloaded
C<$JSON::PP::false> and C<$JSON::PP::true> objects.
With this method you can specify your own boolean values for decoding -
cpan/JSON-PP/lib/JSON/PP.pm view on Meta::CPAN
(and add a C<TO_JSON> method if necessary).
Calling this method without any arguments will reset the booleans
to their default values.
C<get_boolean_values> will return both C<$false> and C<$true> values, or
the empty list when they are set to the default.
=head2 core_bools
$json->core_bools([$enable]);
If C<$enable> is true (or missing), then C<decode>, will produce standard
perl boolean values. Equivalent to calling:
$json->boolean_values(!!1, !!0)
C<get_core_bools> will return true if this has been set. On perl 5.36, it will
also return true if the boolean values have been set to perl's core booleans
using the C<boolean_values> method.
The methods C<unblessed_bool> and C<get_unblessed_bool> are provided as aliases
for compatibility with L<Cpanel::JSON::XS>.
=head2 filter_json_object
view all matches for this distribution