blib/lib/YAML/XS.pm

filter: Statementstmt 73.9% 85 / 115 Branchbran 72.7% 16 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 54.8% 17 / 31 Podpod 0.0% 0 / 2 totaltotal 68.0% 119 / 175 CC 14 SCAR 10.1
CC
14
Cov
73%
__ANON__
7.8
DumpFile
4.1
__qr_loader
3.0
CRAP 2.7
↑ Summary blib/lib/YAML/LibYAML.pm »
1 53 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package YAML::XS;
4 53 our $VERSION = 'v0.910.1'; # TRIAL VERSION
5  
6 53 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 53 @YAML::XS::EXPORT = qw(Load Dump);
9 53 @YAML::XS::EXPORT_OK = qw(LoadFile DumpFile);
10 53 %YAML::XS::EXPORT_TAGS = (
11 all => [qw(Dump Load LoadFile DumpFile)],
12 );
13 our (
14 53 $Boolean,
15 $DumpCode,
16 $ForbidDuplicateKeys,
17 $Indent,
18 $LoadBlessed,
19 $LoadCode,
20 $UseCode,
21 );
22 53 $ForbidDuplicateKeys = 0;
23 # $YAML::XS::UseCode = 0;
24 # $YAML::XS::DumpCode = 0;
25 # $YAML::XS::LoadCode = 0;
26  
27 53 $YAML::XS::QuoteNumericStrings = 1;
28  
29 53 ▶use YAML::XS::LibYAML qw(Load Dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 53 ▶use Scalar::Util qw/ openhandle /;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 5 ▶sub DumpFile {
Subroutine DumpFile: called CC=4 SCAR=14.1
Pod undocumented
33 5 my $OUT;
34 5 my $filename = shift;
35 5 ▶ if (openhandle $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (&openhandle($filename)) { } 2 3 5
36 2 $OUT = $filename;
37 }
38 else {
39 3 my $mode = '>';
40 3 ▶ if ($filename =~ /^\s*(>{1,2})\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ /^\s*(>{1,2})\s*(.*)$/) 0 3 3
41 0 ($mode, $filename) = ($1, $2);
42 }
43 3 ▶ open $OUT, $mode, $filename
Branch: 1 branch
BranchTrueFalseTotal
open $OUT, $mode, $filename or die "Can't open '${filename}' for output:\n$!" 3 0 3
44 or die "Can't open '$filename' for output:\n$!";
45 }
46 5 local $/ = "\n"; # reset special to "sane"
47 5 print $OUT YAML::XS::LibYAML::Dump(@_);
48 }
49  
50 7 ▶sub LoadFile {
Subroutine LoadFile: called CC=3 SCAR=11.0
Pod undocumented
51 7 my $IN;
52 7 my $filename = shift;
53 7 ▶ if (openhandle $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (&openhandle($filename)) { } 2 5 7
54 2 $IN = $filename;
55 }
56 else {
57 5 ▶ open $IN, '<', $filename
Branch: 1 branch
BranchTrueFalseTotal
open $IN, "<", $filename or die "Can't open '${filename}' for input:\n$!" 5 0 5
58 or die "Can't open '$filename' for input:\n$!";
59 }
60 7 return YAML::XS::LibYAML::Load(do { local $/; local $_ = <$IN> });
61 }
62  
63  
64 # XXX The following code should be moved from Perl to C.
65 1 ▶$YAML::XS::coderef2text = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
66 1 my $coderef = shift;
67 1 require B::Deparse;
68 1 my $deparse = B::Deparse->new();
69 1 my $text;
70 1 eval {
71 1 local $^W = 0;
72 1 $text = $deparse->coderef2text($coderef);
73 };
74 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
75 0 warn "YAML::XS failed to dump code ref:\n$@";
76 0 return;
77 }
78 1 $text =~ s[BEGIN \{\$\{\^WARNING_BITS\} = "UUUUUUUUUUUU\\001"\}]
79 [use warnings;]g;
80  
81 1 return $text;
82 53 };
83  
84 2 ▶$YAML::XS::glob2hash = sub {
Subroutine __ANON__: called CC=5 SCAR=20.5
85 2 my $hash = {};
86 2 for my $type (qw(PACKAGE NAME SCALAR ARRAY HASH CODE IO)) {
87 14 my $value = *{$_[0]}{$type};
88 14 ▶ $value = $$value if $type eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "SCALAR" 2 12 14
89 14 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 7 7 14
90 7 ▶ if ($type eq 'IO') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "IO") 0 7 7
91 0 my @stats = qw(device inode mode links uid gid rdev size
92 atime mtime ctime blksize blocks);
93 0 undef $value;
94 0 $value->{stat} = {};
95 0 map {$value->{stat}{shift @stats} = $_} stat(*{$_[0]});
96 0 $value->{fileno} = fileno(*{$_[0]});
97 {
98 0 local $^W;
99 0 $value->{tell} = tell(*{$_[0]});
100 }
101 }
102 7 $hash->{$type} = $value;
103 }
104 }
105 2 return $hash;
106 53 };
107  
108 53 ▶use constant _QR_MAP => {
Subroutine BEGIN: called CC=1 SCAR=2.8
109 5 ▶ '' => sub { qr{$_[0]} },
Subroutine __ANON__: called CC=1 SCAR=0.0
110 0 ▶ x => sub { qr{$_[0]}x },
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 0 ▶ i => sub { qr{$_[0]}i },
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 0 ▶ s => sub { qr{$_[0]}s },
Subroutine __ANON__: not called CC=1 SCAR=6.9
113 0 ▶ m => sub { qr{$_[0]}m },
Subroutine __ANON__: not called CC=1 SCAR=6.9
114 0 ▶ ix => sub { qr{$_[0]}ix },
Subroutine __ANON__: not called CC=1 SCAR=6.9
115 0 ▶ sx => sub { qr{$_[0]}sx },
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 0 ▶ mx => sub { qr{$_[0]}mx },
Subroutine __ANON__: not called CC=1 SCAR=6.9
117 0 ▶ si => sub { qr{$_[0]}si },
Subroutine __ANON__: not called CC=1 SCAR=6.9
118 1 ▶ mi => sub { qr{$_[0]}mi },
Subroutine __ANON__: called CC=1 SCAR=0.0
119 0 ▶ ms => sub { qr{$_[0]}sm },
Subroutine __ANON__: not called CC=1 SCAR=6.9
120 0 ▶ six => sub { qr{$_[0]}six },
Subroutine __ANON__: not called CC=1 SCAR=6.9
121 0 ▶ mix => sub { qr{$_[0]}mix },
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 0 ▶ msx => sub { qr{$_[0]}msx },
Subroutine __ANON__: not called CC=1 SCAR=6.9
123 0 ▶ msi => sub { qr{$_[0]}msi },
Subroutine __ANON__: not called CC=1 SCAR=6.9
124 2 ▶ msix => sub { qr{$_[0]}msix },
Subroutine __ANON__: called CC=1 SCAR=0.0
125 53 };
126  
127 11 ▶sub __qr_loader {
Subroutine __qr_loader: called CC=3 SCAR=11.1
128 11 ▶ if ($_[0] =~ /\A \(\? ([\^uixsm]*) (?:- (?:[ixsm]*))? : (.*) \) \z/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /\A \(\? ([\^uixsm]*) (?:- (?:[ixsm]*))? : (.*) \) \z/x) 8 3 11
129 8 my ($flags, $re) = ($1, $2);
130 8 $flags =~ s/^\^//;
131 8 $flags =~ tr/u//d;
132 8 ▶ my $sub = _QR_MAP->{$flags} || _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; } }->{$flags} || { => 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
800
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]/; } , 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; } }->{$flags} { => 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; } }->{$flags}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
133 8 my $qr = &$sub($re);
134 8 return $qr;
135 }
136 3 return qr/$_[0]/;
137 }
138  
139 2 ▶sub __code_loader {
Subroutine __code_loader: called CC=2 SCAR=7.1
140 2 my ($string) = @_;
141 2 ▶ my $sub = eval "sub $string";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
142 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
143 0 warn "YAML::XS failed to load sub: $@";
144 0 ▶ return sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
145 }
146 2 return $sub;
147 }
148  
149 53 1;
↑ Summary blib/lib/YAML/LibYAML.pm »