Old/Types.pm

filter: Statementstmt 71.9% 113 / 157 Branchbran 66.0% 33 / 50 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 42.1% 16 / 38 Podpod n/a totaltotal 65.6% 166 / 253 SCAR 40.3
CC
31
Cov
70%
yaml_load
11.3
yaml_dump
10.1
yaml_dump
8.2
CRAP 56.2
« Old/Dumper.pm ↑ Summary Old/Dumper/Base.pm »
1 package YAML::Old::Types;
2  
3 35 ▶use YAML::Old::Mo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use YAML::Old::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # XXX These classes and their APIs could still use some refactoring,
7 # but at least they work for now.
8 #-------------------------------------------------------------------------------
9 package YAML::Old::Type::blessed;
10  
11 35 ▶use YAML::Old::Mo; # XXX
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub yaml_dump {
14 27 ▶ my $self = shift;
Subroutine yaml_dump: called CC=4 SCAR=13.9
15 27 my ($value) = @_;
16 27 my ($class, $type) = YAML::Old::Mo::Object->node_info($value);
17 35 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 27 my $kind = lc($type) . ':';
19 27 ▶ my $tag = ${$class . '::ClassTag'} ||
Condition100%2/2
${$class . '::ClassTag';} || "!perl/$kind$class"
l!l
126
MC/DC100%1/1
${$class . '::ClassTag';} || "!perl/$kind$class"
${$class . '::ClassTag';}
Truth table100%2/2
A
A= ${$class . '::ClassTag';}
Aresult
11
00
20 "!perl/$kind$class";
21 27 ▶ if ($type eq 'REF') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'REF') { } 1 26 27
elsif ($type eq 'SCALAR') { } 7 19 26
22 YAML::Old::Node->new(
23 1 {(&YAML::VALUE, ${$_[0]})}, $tag
24 );
25 }
26 elsif ($type eq 'SCALAR') {
27 7 $_[1] = $$value;
28 7 YAML::Old::Node->new($_[1], $tag);
29 } else {
30 19 YAML::Old::Node->new($value, $tag);
31 }
32 }
33  
34 #-------------------------------------------------------------------------------
35 package YAML::Old::Type::undef;
36  
37 sub yaml_dump {
38 0 ▶ my $self = shift;
Subroutine yaml_dump: not called CC=1 SCAR=6.9
39 }
40  
41 sub yaml_load {
42 0 ▶ my $self = shift;
Subroutine yaml_load: not called CC=1 SCAR=6.9
43 }
44  
45 #-------------------------------------------------------------------------------
46 package YAML::Old::Type::glob;
47  
48 sub yaml_dump {
49 5 ▶ my $self = shift;
Subroutine yaml_dump: called CC=6 SCAR=23.1
50 5 my $ynode = YAML::Old::Node->new({}, '!perl/glob:');
51 5 for my $type (qw(PACKAGE NAME SCALAR ARRAY HASH CODE IO)) {
52 35 my $value = *{$_[0]}{$type};
53 35 ▶ $value = $$value if $type eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "SCALAR" 5 30 35
54 35 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 17 18 35
55 17 ▶ if ($type eq 'IO') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "IO") 0 17 17
56 0 my @stats = qw(device inode mode links uid gid rdev size
57 atime mtime ctime blksize blocks);
58 0 undef $value;
59 0 $value->{stat} = YAML::Old::Node->new({});
60 0 ▶ if ($value->{fileno} = fileno(*{$_[0]})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->{"fileno"} = fileno do { $_[0] }) 0 0 0
61 0 local $^W;
62 0 map {$value->{stat}{shift @stats} = $_} stat(*{$_[0]});
63 0 $value->{tell} = tell(*{$_[0]});
64 }
65 }
66 17 $ynode->{$type} = $value;
67 }
68 }
69 5 return $ynode;
70 }
71  
72 sub yaml_load {
73 4 ▶ my $self = shift;
Subroutine yaml_load: called CC=8 SCAR=20.9
74 4 my ($node, $class, $loader) = @_;
75 4 my ($name, $package);
76 4 ▶ if (defined $node->{NAME}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{'NAME'}) { } 3 1 4
77 3 $name = $node->{NAME};
78 3 delete $node->{NAME};
79 }
80 else {
81 1 $loader->warn('YAML_LOAD_WARN_GLOB_NAME');
82 1 return undef;
83 }
84 3 ▶ if (defined $node->{PACKAGE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{'PACKAGE'}) { } 2 1 3
85 2 $package = $node->{PACKAGE};
86 2 delete $node->{PACKAGE};
87 }
88 else {
89 1 $package = 'main';
90 }
91 35 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
92 3 ▶ if (exists $node->{SCALAR}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"SCALAR"}) 2 1 3
93 2 *{"${package}::$name"} = \$node->{SCALAR};
94 2 delete $node->{SCALAR};
95 }
96 3 for my $elem (qw(ARRAY HASH CODE IO)) {
97 12 ▶ if (exists $node->{$elem}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{$elem}) 2 10 12
98 2 ▶ if ($elem eq 'IO') {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem eq "IO") 0 2 2
99 0 $loader->warn('YAML_LOAD_WARN_GLOB_IO');
100 0 delete $node->{IO};
101 0 next;
102 }
103 2 *{"${package}::$name"} = $node->{$elem};
104 2 delete $node->{$elem};
105 }
106 }
107 3 for my $elem (sort keys %$node) {
108 1 $loader->warn('YAML_LOAD_WARN_BAD_GLOB_ELEM', $elem);
109 }
110 3 return *{"${package}::$name"};
111 }
112  
113 #-------------------------------------------------------------------------------
114 package YAML::Old::Type::code;
115  
116 35 my $dummy_warned = 0;
117 35 my $default = '{ "DUMMY" }';
118  
119 sub yaml_dump {
120 6 ▶ my $self = shift;
Subroutine yaml_dump: called CC=8 SCAR=21.1
121 6 my $code;
122 6 my ($dumpflag, $value) = @_;
123 6 my ($class, $type) = YAML::Old::Mo::Object->node_info($value);
124 6 my $tag = "!perl/code";
125 6 ▶ $tag .= ":$class" if defined $class;
Branch: 1 branch
BranchTrueFalseTotal
if defined $class 1 5 6
126 6 ▶ if (not $dumpflag) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dumpflag) { } 1 5 6
127 1 $code = $default;
128 }
129 else {
130 5 ▶ bless $value, "CODE" if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 1 4 5
131 35 ▶ eval { use B::Deparse };
Subroutine BEGIN: called CC=1 SCAR=0.0
132 5 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
133 5 my $deparse = B::Deparse->new();
134 5 eval {
135 5 local $^W = 0;
136 5 $code = $deparse->coderef2text($value);
137 };
138 5 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
139 0 ▶ warn YAML::YAML_DUMP_WARN_DEPARSE_FAILED() if $^W;
Branch: 1 branch
BranchTrueFalseTotal
if $^W 0 0 0
140 0 $code = $default;
141 }
142 5 ▶ bless $value, $class if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 1 4 5
143 5 chomp $code;
144 5 $code .= "\n";
145 }
146 6 $_[2] = $code;
147 6 YAML::Old::Node->new($_[2], $tag);
148 }
149  
150 sub yaml_load {
151 4 ▶ my $self = shift;
Subroutine yaml_load: called CC=5 SCAR=24.2
152 4 my ($node, $class, $loader) = @_;
153 4 ▶ if ($loader->load_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loader->load_code) { } 0 4 4
154 0 my $code = eval "package main; sub $node";
155 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
156 0 $loader->warn('YAML_LOAD_WARN_PARSE_CODE', $@);
157 0 ▶ return sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
158 }
159 else {
160 0 ▶ CORE::bless $code, $class if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 0 0 0
161 0 return $code;
162 }
163 }
164 else {
165 4 ▶ return CORE::bless sub {}, $class if $class;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
if $class 0 4 4
166 4 ▶ return sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
167 }
168 }
169  
170 #-------------------------------------------------------------------------------
171 package YAML::Old::Type::ref;
172  
173 sub yaml_dump {
174 32 ▶ my $self = shift;
Subroutine yaml_dump: called CC=1 SCAR=0.0
175 32 YAML::Old::Node->new({(&YAML::VALUE, ${$_[0]})}, '!perl/ref')
176 }
177  
178 sub yaml_load {
179 0 ▶ my $self = shift;
Subroutine yaml_load: not called CC=2 SCAR=17.9
180 0 my ($node, $class, $loader) = @_;
181 $loader->die('YAML_LOAD_ERR_NO_DEFAULT_VALUE', 'ptr')
182 0 ▶ unless exists $node->{&YAML::VALUE};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$node{&YAML::VALUE} 0 0 0
183 0 return \$node->{&YAML::VALUE};
184 }
185  
186 #-------------------------------------------------------------------------------
187 package YAML::Old::Type::regexp;
188  
189 # XXX Be sure to handle blessed regexps (if possible)
190 sub yaml_dump {
191 0 ▶ die "YAML::Old::Type::regexp::yaml_dump not currently implemented";
Subroutine yaml_dump: not called CC=1 SCAR=6.9
192 }
193  
194 use constant _QR_TYPES => {
195 2 ▶ '' => sub { qr{$_[0]} },
Subroutine __ANON__: called CC=1 SCAR=0.0
196 0 ▶ x => sub { qr{$_[0]}x },
Subroutine __ANON__: not called CC=1 SCAR=6.9
197 0 ▶ i => sub { qr{$_[0]}i },
Subroutine __ANON__: not called CC=1 SCAR=6.9
198 0 ▶ s => sub { qr{$_[0]}s },
Subroutine __ANON__: not called CC=1 SCAR=6.9
199 4 ▶ m => sub { qr{$_[0]}m },
Subroutine __ANON__: called CC=1 SCAR=0.0
200 0 ▶ ix => sub { qr{$_[0]}ix },
Subroutine __ANON__: not called CC=1 SCAR=6.9
201 0 ▶ sx => sub { qr{$_[0]}sx },
Subroutine __ANON__: not called CC=1 SCAR=6.9
202 0 ▶ mx => sub { qr{$_[0]}mx },
Subroutine __ANON__: not called CC=1 SCAR=6.9
203 0 ▶ si => sub { qr{$_[0]}si },
Subroutine __ANON__: not called CC=1 SCAR=6.9
204 0 ▶ mi => sub { qr{$_[0]}mi },
Subroutine __ANON__: not called CC=1 SCAR=6.9
205 0 ▶ ms => sub { qr{$_[0]}sm },
Subroutine __ANON__: not called CC=1 SCAR=6.9
206 0 ▶ six => sub { qr{$_[0]}six },
Subroutine __ANON__: not called CC=1 SCAR=6.9
207 0 ▶ mix => sub { qr{$_[0]}mix },
Subroutine __ANON__: not called CC=1 SCAR=6.9
208 0 ▶ msx => sub { qr{$_[0]}msx },
Subroutine __ANON__: not called CC=1 SCAR=6.9
209 0 ▶ msi => sub { qr{$_[0]}msi },
Subroutine __ANON__: not called CC=1 SCAR=6.9
210 0 ▶ msix => sub { qr{$_[0]}msix },
Subroutine __ANON__: not called CC=1 SCAR=6.9
211 35 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
212  
213 sub yaml_load {
214 6 ▶ my $self = shift;
Subroutine yaml_load: called CC=4 SCAR=14.3
215 6 my ($node, $class) = @_;
216 6 ▶ return qr{$node} unless $node =~ /^\(\?([\^\-xism]*):(.*)\)\z/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $node =~ /^\(\?([\^\-xism]*):(.*)\)\z/s 0 6 6
217 6 my ($flags, $re) = ($1, $2);
218 6 $flags =~ s/-.*//;
219 6 $flags =~ s/^\^//;
220 6 ▶ my $sub = _QR_TYPES->{$flags} || sub { qr{$_[0]} };
Subroutine __ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
{ => sub { qr/$_[0]/; } , i => sub { qr/$_[0]/i; } , ix => sub { qr/$_[0]/xi; } , m => sub { qr/$_[0]/m; } , mi => sub { qr/$_[0]/im; } , mix => sub { qr/$_[0]/mix; } , ms => sub { qr/$_[0]/ms; } , msi => sub { qr/$_[0]/ism; } , msix => sub { qr/$_[0]/imsx; } , msx => sub { qr/$_[0]/msx; } , mx => sub { qr/$_[0]/mx; } , s => sub { qr/$_[0]/s; } , si => sub { qr/$_[0]/is; } , six => sub { qr/$_[0]/six; } , sx => sub { qr/$_[0]/sx; } , x => sub { qr/$_[0]/x; } }->{$flags} || sub { qr/$_[0]/; }
l!l&&r!l&&!r
600
MC/DC0%0/2
{ => sub { qr/$_[0]/; } , i => sub { qr/$_[0]/i; } , ix => sub { qr/$_[0]/xi; } , m => sub { qr/$_[0]/m; } , mi => sub { qr/$_[0]/im; } , mix => sub { qr/$_[0]/mix; } , ms => sub { qr/$_[0]/ms; } , msi => sub { qr/$_[0]/ism; } , msix => sub { qr/$_[0]/imsx; } , msx => sub { qr/$_[0]/msx; } , mx => sub { qr/$_[0]/mx; } , s => sub { qr/$_[0]/s; } , si => sub { qr/$_[0]/is; } , six => sub { qr/$_[0]/six; } , sx => sub { qr/$_[0]/sx; } , x => sub { qr/$_[0]/x; } }->{$flags} || sub { qr/$_[0]/; }
{ => sub { qr/$_[0]/; } , i => sub { qr/$_[0]/i; } , ix => sub { qr/$_[0]/xi; } , m => sub { qr/$_[0]/m; } , mi => sub { qr/$_[0]/im; } , mix => sub { qr/$_[0]/mix; } , ms => sub { qr/$_[0]/ms; } , msi => sub { qr/$_[0]/ism; } , msix => sub { qr/$_[0]/imsx; } , msx => sub { qr/$_[0]/msx; } , mx => sub { qr/$_[0]/mx; } , s => sub { qr/$_[0]/s; } , si => sub { qr/$_[0]/is; } , six => sub { qr/$_[0]/six; } , sx => sub { qr/$_[0]/sx; } , x => sub { qr/$_[0]/x; } }->{$flags} sub { qr/$_[0]/; }
Truth table33%1/3
A || B
A= { => sub { qr/$_[0]/; } , i => sub { qr/$_[0]/i; } , ix => sub { qr/$_[0]/xi; } , m => sub { qr/$_[0]/m; } , mi => sub { qr/$_[0]/im; } , mix => sub { qr/$_[0]/mix; } , ms => sub { qr/$_[0]/ms; } , msi => sub { qr/$_[0]/ism; } , msix => sub { qr/$_[0]/imsx; } , msx => sub { qr/$_[0]/msx; } , mx => sub { qr/$_[0]/mx; } , s => sub { qr/$_[0]/s; } , si => sub { qr/$_[0]/is; } , six => sub { qr/$_[0]/six; } , sx => sub { qr/$_[0]/sx; } , x => sub { qr/$_[0]/x; } }->{$flags}B= sub { qr/$_[0]/; }
ABresult
1X1
011
000
221 6 my $qr = &$sub($re);
222 6 ▶ bless $qr, $class if length $class;
Branch: 1 branch
BranchTrueFalseTotal
if length $class 2 4 6
223 6 return $qr;
224 }
225  
226 35 1;
« Old/Dumper.pm ↑ Summary Old/Dumper/Base.pm »