Old/Types.pm

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