diff --git a/lib/YAML/PP/Schema.pm b/lib/YAML/PP/Schema.pm index c2348962..7f2528a3 100644 --- a/lib/YAML/PP/Schema.pm +++ b/lib/YAML/PP/Schema.pm @@ -40,19 +40,16 @@ sub new { $false ||= \&_bool_booleanpm_false; push @bool_class, 'boolean'; } - elsif ($b eq 'perl') { - $true ||= \&_bool_perl_true; - $false ||= \&_bool_perl_false; - } - elsif ($b eq 'perl_experimental') { - $true ||= \&_bool_perl_true; - $false ||= \&_bool_perl_false; - push @bool_class, 'perl_experimental'; + elsif ($b eq 'perl' or $b eq 'perl_experimental') { + push @bool_class, 'perl'; } else { die "Invalid value for 'boolean': '$b'. Allowed: ('perl', 'boolean', 'JSON::PP')"; } } + # Ensure booleans are resolved + $true ||= \&_bool_perl_true; + $false ||= \&_bool_perl_false; my %representers = ( 'undef' => undef, diff --git a/lib/YAML/PP/Schema/Core.pm b/lib/YAML/PP/Schema/Core.pm index 0bed290e..bd51351b 100644 --- a/lib/YAML/PP/Schema/Core.pm +++ b/lib/YAML/PP/Schema/Core.pm @@ -97,9 +97,9 @@ sub register { if ($schema->bool_class) { for my $class (@{ $schema->bool_class }) { - if ($class eq 'perl_experimental') { + if ($class eq 'perl') { $schema->add_representer( - bool => $class, + bool => 1, code => \&represent_bool, ); next; diff --git a/lib/YAML/PP/Schema/JSON.pm b/lib/YAML/PP/Schema/JSON.pm index d3abe0c1..c96fe193 100644 --- a/lib/YAML/PP/Schema/JSON.pm +++ b/lib/YAML/PP/Schema/JSON.pm @@ -104,9 +104,9 @@ sub register { if ($schema->bool_class) { for my $class (@{ $schema->bool_class }) { - if ($class eq 'perl_experimental') { + if ($class eq 'perl') { $schema->add_representer( - bool => $class, + bool => 1, code => \&represent_bool, ); next; diff --git a/lib/YAML/PP/Schema/YAML1_1.pm b/lib/YAML/PP/Schema/YAML1_1.pm index 5c8f8c1f..4f9a0dd2 100644 --- a/lib/YAML/PP/Schema/YAML1_1.pm +++ b/lib/YAML/PP/Schema/YAML1_1.pm @@ -179,6 +179,13 @@ sub register { if ($schema->bool_class) { for my $class (@{ $schema->bool_class }) { + if ($class eq 'perl') { + $schema->add_representer( + bool => 1, + code => \&represent_bool, + ); + next; + } $schema->add_representer( class_equals => $class, code => \&represent_bool, diff --git a/t/22.dump-bool.t b/t/22.dump-bool.t index 1c4add2c..93403828 100644 --- a/t/22.dump-bool.t +++ b/t/22.dump-bool.t @@ -124,6 +124,21 @@ true1: true EOM cmp_ok($yaml, 'eq', $exp_json_pp, "perl_experimental dump"); } +SKIP: { + skip "perl version < v5.36", 1 unless $] >= 5.036000; + my $data = { + "true1" => !!1, + "false1" => !!0, + }; + my $yppd = YAML::PP->new(boolean => ''); + my $yaml = $yppd->dump_string($data); + my $exp_json_pp = <<'EOM'; +--- +false1: '' +true1: 1 +EOM + cmp_ok($yaml, 'eq', $exp_json_pp, "no booleans dump"); +} SKIP: { skip "perl version < v5.36", 3 unless $] >= 5.036000; diff --git a/t/51.directives.t b/t/51.directives.t index 2a85bb63..5a9ec7a8 100644 --- a/t/51.directives.t +++ b/t/51.directives.t @@ -208,7 +208,7 @@ EOM my %args= ( schema => [qw/ + /], - boolean => 'perl', + boolean => '', version_directive => 1, );