blib/lib/YAML/Syck.pm

filter: Statementstmt 82.0% 96 / 117 Branchbran 79.3% 46 / 58 Conditioncond 66.6% 18 / 27 MC/DCmcdc 50.0% 9 / 18 Subroutinesub 56.2% 18 / 32 Podpod 44.4% 4 / 9 totaltotal 73.1% 191 / 261 CC 43 SCAR 16.6
CC
43
Cov
79%
DumpFile
12.9
Load
6.1
LoadBytes
6.1
CRAP 5.2
« blib/lib/JSON/Syck.pm ↑ Summary blib/lib/YAML/Dumper/Syck.pm »
1 package YAML::Syck;
2  
3 # See documentation after the __END__ mark.
4  
5 72 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 72 our ( $Headless, $SingleQuote, $ImplicitBinary, $ImplicitTyping, $ImplicitUnicode, $UseCode, $LoadCode, $DumpCode, $DeparseObject, $MaxDepth );
8  
9 72 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 72 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 72 ▶use XSLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 72 our $VERSION = '1.47';
14 72 our @EXPORT = qw( Dump Load DumpFile LoadFile );
15 72 our @EXPORT_OK = qw( DumpInto LoadBytes LoadUTF8 DumpBytes DumpUTF8 );
16 72 our @ISA = qw( Exporter );
17  
18 72 our $SortKeys = 1;
19 72 our $LoadBlessed = 0;
20  
21 72 XSLoader::load( 'YAML::Syck', $VERSION );
22  
23 72 ▶use constant QR_MAP => {
Subroutine BEGIN: called CC=1 SCAR=3.4
24 5 ▶ '' => sub { qr{$_[0]} },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 0 ▶ x => sub { qr{$_[0]}x },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 2 ▶ i => sub { qr{$_[0]}i },
Subroutine __ANON__: called CC=1 SCAR=0.0
27 0 ▶ s => sub { qr{$_[0]}s },
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 ▶ m => sub { qr{$_[0]}m },
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 0 ▶ ix => sub { qr{$_[0]}ix },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 ▶ sx => sub { qr{$_[0]}sx },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 ▶ mx => sub { qr{$_[0]}mx },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 ▶ si => sub { qr{$_[0]}si },
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 ▶ mi => sub { qr{$_[0]}mi },
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 ▶ ms => sub { qr{$_[0]}sm },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 ▶ six => sub { qr{$_[0]}six },
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 ▶ mix => sub { qr{$_[0]}mix },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 0 ▶ msx => sub { qr{$_[0]}msx },
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 ▶ msi => sub { qr{$_[0]}msi },
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 ▶ msix => sub { qr{$_[0]}msix },
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 72 };
41  
42 7 ▶sub __qr_helper {
Subroutine __qr_helper: called CC=3 SCAR=13.3
43 7 ▶ if ( $_[0] =~ /\A \(\? \^? ([ixsm]*) (?:- (?:[ixsm]*))? : (.*) \) \z/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /\A \(\? \^? ([ixsm]*) (?:- (?:[ixsm]*))? : (.*) \) \z/x) { } 7 0 7
44 7 ▶ my $sub = QR_MAP()->{$1} || QR_MAP()->{''};
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; } }->{$1} || { => 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; } }->{''}
l!l&&r!l&&!r
700
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; } }->{$1} || { => 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; } }->{''}
{ => 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; } }->{$1} { => 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; } }->{''}
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; } }->{$1}B= { => 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; } }->{''}
ABresult
1X1
011
000
45 7 &$sub($2);
46 }
47 else {
48 0 qr/$_[0]/;
49 }
50 }
51  
52 1213 ▶sub Dump {
Subroutine Dump: called CC=2 SCAR=6.9
Pod undocumented
53 $#_
54 1213 ▶ ? join( '', map { YAML::Syck::DumpYAML($_) } @_ )
Branch: 1 branch
BranchTrueFalseTotal
$#_ ? : 5 1208 1213
55 : YAML::Syck::DumpYAML( $_[0] );
56 }
57  
58 2194 ▶sub Load {
Subroutine Load: called CC=6 SCAR=18.1
Pod undocumented
59 2194 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 212 1982 2194
60 212 ▶ return unless defined $_[0] && length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and length $_[0] 2 210 212
Condition100%3/3
defined $_[0] and length $_[0]
!ll&&!rl&&r
11210
MC/DC100%2/2
defined $_[0] and length $_[0]
defined $_[0] length $_[0]
Truth table100%3/3
A and B
A= defined $_[0]B= length $_[0]
ABresult
0X0
100
111
61 210 my ($rv) = YAML::Syck::LoadYAML( $_[0] );
62 210 ▶ return unless defined $rv && ref $rv eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv and ref $rv eq "ARRAY" 0 210 210
Condition33%1/3
defined $rv and ref $rv eq "ARRAY"
!ll&&!rl&&r
00210
MC/DC0%0/2
defined $rv and ref $rv eq "ARRAY"
defined $rv ref $rv eq "ARRAY"
Truth table33%1/3
A and B
A= defined $rvB= ref $rv eq "ARRAY"
ABresult
0X0
100
111
63 210 @{$rv};
64 }
65 else {
66 1982 @_ = $_[0];
67 1982 goto &YAML::Syck::LoadYAML;
68 }
69 }
70  
71 552 ▶sub _is_glob {
Subroutine _is_glob: called CC=6 SCAR=17.9
72 552 my $h = shift;
73  
74 552 ▶ return 1 if ( ref($h) eq 'GLOB' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $h eq "GLOB" 23 529 552
75 529 ▶ return 1 if ( ref( \$h ) eq 'GLOB' );
Branch: 1 branch
BranchTrueFalseTotal
if ref \$h eq "GLOB" 6 523 529
76 523 ▶ return 1 if ( index( ref($h), 'IO::' ) == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if index(ref $h, "IO::") == 0 4 519 523
77 519 ▶ return 1 if ( ref($h) && UNIVERSAL::isa($h, 'IO::Handle') );
Branch: 1 branch
BranchTrueFalseTotal
if ref $h and UNIVERSAL::isa($h, "IO::Handle") 2 517 519
Condition66%2/3
ref $h and UNIVERSAL::isa($h, "IO::Handle")
!ll&&!rl&&r
51702
MC/DC50%1/2
ref $h and UNIVERSAL::isa($h, "IO::Handle")
ref $h UNIVERSAL::isa($h, "IO::Handle")
Truth table66%2/3
A and B
A= ref $hB= UNIVERSAL::isa($h, "IO::Handle")
ABresult
0X0
100
111
78  
79 517 return;
80 }
81  
82 15 ▶sub DumpFile {
Subroutine DumpFile: called CC=11 SCAR=25.6
Pod undocumented
83 15 my $file = shift;
84 15 ▶ if ( _is_glob($file) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_glob($file)) { } 11 4 15
85 11 ▶ if ( tied(*$file) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied *$file) { } 3 8 11
86 # Tied filehandles (IO::String, IO::Scalar, etc.) don't support
87 # C-level PerlIO_write. Fall back to Perl-level print.
88 3 for (@_) {
89 3 ▶ print $file YAML::Syck::Dump($_)
Branch: 1 branch
BranchTrueFalseTotal
print $file Dump($_) or die "Error writing to filehandle ${file}: $!\n" 3 0 3
90 or die "Error writing to filehandle $file: $!\n";
91 }
92 }
93 else {
94 8 for (@_) {
95 8 my $err = YAML::Syck::DumpYAMLFile( $_, $file );
96 8 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 8 8
97 0 $! = 0 + $err;
98 0 die "Error writing to filehandle $file: $!\n";
99 }
100 }
101 }
102 }
103 else {
104 4 ▶ open( my $fh, '>', $file ) or die "Cannot write to $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or die "Cannot write to ${file}: $!" 3 1 4
105 3 for (@_) {
106 3 my $err = YAML::Syck::DumpYAMLFile( $_, $fh );
107 3 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 3 3
108 0 $! = 0 + $err;
109 0 die "Error writing to file $file: $!\n";
110 }
111 }
112 3 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Error writing to file ${file}: $!\n" 3 0 3
113 or die "Error writing to file $file: $!\n";
114 }
115 14 return 1;
116 }
117  
118 516 ▶sub LoadFile {
Subroutine LoadFile: called CC=5 SCAR=16.1
Pod undocumented
119 516 my $file = shift;
120 516 ▶ if ( _is_glob($file) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_glob($file)) { } 9 507 516
121 Load(
122 9 do { local $/; <$file> }
123 );
124 }
125 else {
126 507 ▶ if ( !-e $file || -z $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $file or -z $file) 2 505 507
Condition100%3/3
not -e $file or -z $file
l!l&&r!l&&!r
11505
MC/DC100%2/2
not -e $file or -z $file
not -e $file -z $file
Truth table100%3/3
not(A) or B
A= not -e $fileB= -z $file
ABresult
1X1
011
000
127 2 die("'$file' is empty or non-existent");
128 }
129 505 ▶ open( my $fh, '<', $file ) or die "Cannot read from $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Cannot read from ${file}: $!" 504 1 505
130 Load(
131 504 do { local $/; <$fh> }
132 );
133 }
134 }
135  
136 6 ▶sub LoadBytes {
Subroutine LoadBytes: called CC=6 SCAR=18.1
Pod documented
137 6 my ($str) = @_;
138 6 utf8::downgrade($str);
139 6 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 4 2 6
140 4 ▶ return unless defined $str && length $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str and length $str 2 2 4
Condition100%3/3
defined $str and length $str
!ll&&!rl&&r
112
MC/DC100%2/2
defined $str and length $str
defined $str length $str
Truth table100%3/3
A and B
A= defined $strB= length $str
ABresult
0X0
100
111
141 2 my ($rv) = YAML::Syck::LoadYAML($str);
142 2 ▶ return unless defined $rv && ref $rv eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv and ref $rv eq "ARRAY" 0 2 2
Condition33%1/3
defined $rv and ref $rv eq "ARRAY"
!ll&&!rl&&r
002
MC/DC0%0/2
defined $rv and ref $rv eq "ARRAY"
defined $rv ref $rv eq "ARRAY"
Truth table33%1/3
A and B
A= defined $rvB= ref $rv eq "ARRAY"
ABresult
0X0
100
111
143 2 return @{$rv};
144 }
145 2 return YAML::Syck::LoadYAML($str);
146 }
147  
148 6 ▶sub LoadUTF8 {
Subroutine LoadUTF8: called CC=6 SCAR=18.1
Pod documented
149 6 my ($str) = @_;
150 6 local $YAML::Syck::ImplicitUnicode = 1;
151 6 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 4 2 6
152 4 ▶ return unless defined $str && length $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str and length $str 2 2 4
Condition100%3/3
defined $str and length $str
!ll&&!rl&&r
112
MC/DC100%2/2
defined $str and length $str
defined $str length $str
Truth table100%3/3
A and B
A= defined $strB= length $str
ABresult
0X0
100
111
153 2 my ($rv) = YAML::Syck::LoadYAML($str);
154 2 ▶ return unless defined $rv && ref $rv eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv and ref $rv eq "ARRAY" 0 2 2
Condition33%1/3
defined $rv and ref $rv eq "ARRAY"
!ll&&!rl&&r
002
MC/DC0%0/2
defined $rv and ref $rv eq "ARRAY"
defined $rv ref $rv eq "ARRAY"
Truth table33%1/3
A and B
A= defined $rvB= ref $rv eq "ARRAY"
ABresult
0X0
100
111
155 2 return @{$rv};
156 }
157 2 return YAML::Syck::LoadYAML($str);
158 }
159  
160 2 ▶sub DumpBytes {
Subroutine DumpBytes: called CC=3 SCAR=12.5
Pod documented
161 my $result = $#_
162 0 ▶ ? join( '', map { YAML::Syck::DumpYAML($_) } @_ )
Branch: 1 branch
BranchTrueFalseTotal
$#_ ? : 0 2 2
163 : YAML::Syck::DumpYAML( $_[0] );
164 2 ▶ utf8::encode($result) if utf8::is_utf8($result);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($result) 0 2 2
165 2 return $result;
166 }
167  
168 1 ▶sub DumpUTF8 {
Subroutine DumpUTF8: called CC=2 SCAR=8.1
Pod documented
169 1 local $YAML::Syck::ImplicitUnicode = 1;
170 $#_
171 0 ▶ ? join( '', map { YAML::Syck::DumpYAML($_) } @_ )
Branch: 1 branch
BranchTrueFalseTotal
$#_ ? : 0 1 1
172 : YAML::Syck::DumpYAML( $_[0] );
173 }
174  
175 8 ▶sub DumpInto {
Subroutine DumpInto: called CC=3 SCAR=11.1
Pod undocumented
176 8 my $bufref = shift;
177 8 ▶ ( ref $bufref ) or die "DumpInto not given reference to output buffer\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $bufref or die "DumpInto not given reference to output buffer\n" 8 0 8
178 8 YAML::Syck::DumpYAMLInto( $_, $bufref ) for @_;
179 8 1;
180 }
181  
182 72 1;
183  
184 __END__
« blib/lib/JSON/Syck.pm ↑ Summary blib/lib/YAML/Dumper/Syck.pm »