blib/lib/JSON/Syck.pm

filter: Statementstmt 92.0% 46 / 50 Branchbran 77.2% 17 / 22 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 86.0% 74 / 86 CC 13 SCAR 17.8
CC
13
Cov
88%
DumpFile
9.3
LoadFile
5.0
DumpInto
2.0
CRAP 5.9
↑ Summary blib/lib/YAML/Syck.pm »
1 package JSON::Syck;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 20 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use YAML::Syck ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 20 our $VERSION = '1.47';
8 20 our @EXPORT_OK = qw( Load Dump LoadFile DumpFile DumpInto );
9 20 our @ISA = qw/Exporter/;
10  
11 20 *Load = \&YAML::Syck::LoadJSON;
12 20 *Dump = \&YAML::Syck::DumpJSON;
13  
14 9 ▶sub DumpFile {
Subroutine DumpFile: called CC=8 SCAR=22.3
Pod undocumented
15 9 my $file = shift;
16 9 ▶ if ( YAML::Syck::_is_glob($file) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (YAML::Syck::_is_glob($file)) { } 7 2 9
17 7 ▶ if ( tied(*$file) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied *$file) { } 2 5 7
18 # Tied filehandles (IO::String, IO::Scalar, etc.) don't support
19 # C-level PerlIO_write. Fall back to Perl-level print.
20 2 ▶ print $file YAML::Syck::DumpJSON( $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
print $file YAML::Syck::DumpJSON($_[0]) or die "Error writing to filehandle ${file}: $!\n" 2 0 2
21 or die "Error writing to filehandle $file: $!\n";
22 }
23 else {
24 5 my $err = YAML::Syck::DumpJSONFile( $_[0], $file );
25 5 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 5 5
26 0 $! = 0 + $err;
27 0 die "Error writing to filehandle $file: $!\n";
28 }
29 }
30 }
31 else {
32 2 ▶ open( my $fh, '>', $file ) or die "Cannot write to $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or die "Cannot write to ${file}: $!" 1 1 2
33 1 my $err = YAML::Syck::DumpJSONFile( $_[0], $fh );
34 1 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 1 1
35 0 $! = 0 + $err;
36 0 die "Error writing to file $file: $!\n";
37 }
38 1 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Error writing to file ${file}: $!\n" 1 0 1
39 or die "Error writing to file $file: $!\n";
40 }
41 8 return 1;
42 }
43  
44 12 ▶sub LoadFile {
Subroutine LoadFile: called CC=5 SCAR=16.1
Pod undocumented
45 12 my $file = shift;
46 12 ▶ if ( YAML::Syck::_is_glob($file) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (YAML::Syck::_is_glob($file)) { } 8 4 12
47 YAML::Syck::LoadJSON(
48 8 do { local $/; <$file> }
49 );
50 }
51 else {
52 4 ▶ if ( !-e $file || -z $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $file or -z $file) 2 2 4
Condition100%3/3
not -e $file or -z $file
l!l&&r!l&&!r
112
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
53 2 die("'$file' is non-existent or empty");
54 }
55 2 ▶ open( my $fh, '<', $file ) or die "Cannot read from $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Cannot read from ${file}: $!" 1 1 2
56 YAML::Syck::LoadJSON(
57 1 do { local $/; <$fh> }
58 );
59 }
60 }
61  
62 7 ▶sub DumpInto {
Subroutine DumpInto: called CC=2 SCAR=7.0
Pod undocumented
63 7 my $bufref = shift;
64 7 ▶ ( 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" 7 0 7
65 7 YAML::Syck::DumpJSONInto( $_[0], $bufref );
66 7 1;
67 }
68  
69 20 $JSON::Syck::ImplicitTyping = 1;
70 20 $JSON::Syck::MaxDepth = 512;
71 20 $JSON::Syck::Headless = 1;
72 20 $JSON::Syck::ImplicitUnicode = 0;
73 20 $JSON::Syck::SingleQuote = 0;
74  
75 20 1;
76  
77 __END__
↑ Summary blib/lib/YAML/Syck.pm »