Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Dec 28, 2023
1 parent 8a2ccd5 commit 53793eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/YAML/PP/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ sub new {
coderef => undef,
glob => undef,
tied_equals => {},
bool => undef,
);
my $self = bless {
yaml_version => $yaml_version,
Expand Down Expand Up @@ -238,13 +239,13 @@ sub add_representer {
push @$rep, [ $args{class_matches}, $args{code} ];
return;
}
if (my $bool = $args{bool} and $] >= 5.036000) {
$representers->{bool} = {
code => $args{code},
};
return;
}
if (my $class_equals = $args{class_equals}) {
if ($] >= 5.036000 and $class_equals eq 'perl_experimental') {
$representers->{bool} = {
code => $args{code},
};
return;
}
my $rep = $representers->{class_equals};
$rep->{ $class_equals } = {
code => $args{code},
Expand Down
7 changes: 7 additions & 0 deletions lib/YAML/PP/Schema/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ sub register {

if ($schema->bool_class) {
for my $class (@{ $schema->bool_class }) {
if ($class eq 'perl_experimental') {
$schema->add_representer(
bool => $class,
code => \&represent_bool,
);
next;
}
$schema->add_representer(
class_equals => $class,
code => \&represent_bool,
Expand Down
9 changes: 9 additions & 0 deletions t/14.load-bool.t
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@ SKIP: {
is(! $data_jp->{FALSE}, 1, 'JSON::PP::Boolean false');
}

SKIP: {
skip "perl 5.36 required for this test", 3 unless $] >= 5.036000;
my $is_bool = eval 'use experimental qw/ builtin /; sub { builtin::is_bool($_[0]) }';
my $ypp = YAML::PP->new(boolean => 'perl_experimental');
my $data_jp = $ypp->load_string($yaml);
ok $is_bool->($data_jp->{TRUE}) && $data_jp->{TRUE}, 'builtin::is_bool truw';
ok $is_bool->($data_jp->{FALSE}) && ! $data_jp->{FALSE}, 'builtin::is_bool false';
}

done_testing;

0 comments on commit 53793eb

Please sign in to comment.