| 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
| |||||||||||||||||||||||||||||
| 17 | 7 | ▶ | if ( tied(*$file) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 33 | 1 | my $err = YAML::Syck::DumpJSONFile( $_[0], $fh ); | |||||||||||||||||||||||||||
| 34 | 1 | ▶ | if ($err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | $! = 0 + $err; | |||||||||||||||||||||||||||
| 36 | 0 | die "Error writing to file $file: $!\n"; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 1 | ▶ | close $fh | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 47 | YAML::Syck::LoadJSON( | ||||||||||||||||||||||||||||
| 48 | 8 | do { local $/; <$file> } | |||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||
| 52 | 4 | ▶ | if ( !-e $file || -z $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not -e $file or -z $file
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||