blib/lib/YAML/PP/Schema/Core.pm

filter: Statementstmt 100% 52 / 52 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 100% 66 / 66 CC 11 SCAR 19.2
CC
11
Cov
100%
register
11.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.8
« blib/lib/YAML/PP/Dumper.pm ↑ Summary blib/lib/YAML/PP/Schema/Include.pm »
1 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package YAML::PP::Schema::Core;
4  
5 35 our $VERSION = 'v0.43.0'; # VERSION
6  
7 35 ▶use YAML::PP::Schema::JSON qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
8 represent_int represent_float represent_literal represent_bool
9 represent_undef
10 35 /;
11  
12 35 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 35 ▶use YAML::PP::Common qw/ YAML_PLAIN_SCALAR_STYLE /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 35 my $RE_INT_CORE = qr{^([+-]?(?:[0-9]+))$};
17 35 my $RE_FLOAT_CORE = qr{^([+-]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)(?:[eE][+-]?[0-9]+)?)$};
18 35 my $RE_INT_OCTAL = qr{^0o([0-7]+)$};
19 35 my $RE_INT_HEX = qr{^0x([0-9a-fA-F]+)$};
20  
21 6 ▶sub _from_oct { oct $_[2]->[0] }
Subroutine _from_oct: called CC=1 SCAR=0.0
22 10 ▶sub _from_hex { hex $_[2]->[0] }
Subroutine _from_hex: called CC=1 SCAR=0.0
23  
24 739 ▶sub register {
Subroutine register: called CC=11 SCAR=24.0
Pod documented
25 739 my ($self, %args) = @_;
26 739 my $schema = $args{schema};
27  
28 $schema->add_resolver(
29 tag => 'tag:yaml.org,2002:null',
30 match => [ equals => $_ => undef ],
31 739 ) for (qw/ null NULL Null ~ /, '');
32 $schema->add_resolver(
33 tag => 'tag:yaml.org,2002:bool',
34 match => [ equals => $_ => $schema->true ],
35 739 ) for (qw/ true TRUE True /);
36 $schema->add_resolver(
37 tag => 'tag:yaml.org,2002:bool',
38 match => [ equals => $_ => $schema->false ],
39 739 ) for (qw/ false FALSE False /);
40 739 $schema->add_resolver(
41 tag => 'tag:yaml.org,2002:int',
42 match => [ regex => $RE_INT_CORE => \&YAML::PP::Schema::JSON::_to_int ],
43 );
44 739 $schema->add_resolver(
45 tag => 'tag:yaml.org,2002:int',
46 match => [ regex => $RE_INT_OCTAL => \&_from_oct ],
47 );
48 739 $schema->add_resolver(
49 tag => 'tag:yaml.org,2002:int',
50 match => [ regex => $RE_INT_HEX => \&_from_hex ],
51 );
52 739 $schema->add_resolver(
53 tag => 'tag:yaml.org,2002:float',
54 match => [ regex => $RE_FLOAT_CORE => \&YAML::PP::Schema::JSON::_to_float ],
55 );
56 $schema->add_resolver(
57 tag => 'tag:yaml.org,2002:float',
58 match => [ equals => $_ => 0 + "inf" ],
59 739 ) for (qw/ .inf .Inf .INF +.inf +.Inf +.INF /);
60 $schema->add_resolver(
61 tag => 'tag:yaml.org,2002:float',
62 match => [ equals => $_ => 0 - "inf" ],
63 739 ) for (qw/ -.inf -.Inf -.INF /);
64 $schema->add_resolver(
65 tag => 'tag:yaml.org,2002:float',
66 match => [ equals => $_ => 0 + "nan" ],
67 739 ) for (qw/ .nan .NaN .NAN /);
68 $schema->add_resolver(
69 tag => 'tag:yaml.org,2002:str',
70 739 ▶ match => [ all => sub { $_[1]->{value} } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
71 );
72  
73 739 my $int_flags = B::SVp_IOK;
74 739 my $float_flags = B::SVp_NOK;
75 739 $schema->add_representer(
76 flags => $int_flags,
77 code => \&represent_int,
78 );
79 739 $schema->add_representer(
80 flags => $float_flags,
81 code => \&represent_float,
82 );
83 739 $schema->add_representer(
84 undefined => \&represent_undef,
85 );
86 $schema->add_representer(
87 equals => $_,
88 code => \&represent_literal,
89 739 ) for ("", qw/
90 true TRUE True false FALSE False null NULL Null ~
91 .inf .Inf .INF +.inf +.Inf +.INF -.inf -.Inf -.INF .nan .NaN .NAN
92 /);
93 739 $schema->add_representer(
94 regex => qr{$RE_INT_CORE|$RE_FLOAT_CORE|$RE_INT_OCTAL|$RE_INT_HEX},
95 code => \&represent_literal,
96 );
97  
98 739 ▶ if ($schema->bool_class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->bool_class) 735 4 739
99 735 for my $class (@{ $schema->bool_class }) {
100 735 ▶ if ($class eq 'perl') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "perl") 145 590 735
101 145 $schema->add_representer(
102 bool => 1,
103 code => \&represent_bool,
104 );
105 145 next;
106 }
107 $schema->add_representer(
108 590 class_equals => $class,
109 code => \&represent_bool,
110 );
111 }
112 }
113  
114 739 return;
115 }
116  
117 35 1;
118  
119 __END__
« blib/lib/YAML/PP/Dumper.pm ↑ Summary blib/lib/YAML/PP/Schema/Include.pm »