blib/lib/Process/YAML.pm

filter: Statementstmt 88.3% 68 / 77 Branchbran 62.5% 20 / 32 Conditioncond 55.5% 10 / 18 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 15 / 15 Podpod 100% 2 / 2 totaltotal 77.2% 119 / 154 CC 23 SCAR 23.1
CC
23
Cov
77%
serialize
19.3
deserialize
11.1
BEGIN
3.1
CRAP 10.0
↑ Summary
1 package Process::YAML;
2  
3 # Process that is compatible with Storable after new, and after run.
4  
5 3 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use base 'Process::Serializable';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Fcntl qw/:flock/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use YAML::Syck ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use IO::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use IO::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use IO::String ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Params::Util qw/_INSTANCE/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 $VERSION = '0.04';
19 }
20  
21 3 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.4
22 3 ▶ unless ( IO::String->isa('IO::Handle') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("IO::String"->isa("IO::Handle")) 3 0 3
23 3 push @IO::String::ISA, 'IO::Handle';
24 }
25 3 ▶ unless ( IO::String->isa('IO::Seekable') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("IO::String"->isa("IO::Seekable")) 3 0 3
26 3 push @IO::String::ISA, 'IO::Seekable';
27 }
28 }
29  
30 4 ▶sub serialize {
Subroutine serialize: called CC=13 SCAR=29.6
Pod documented
31 4 my $self = shift;
32  
33 # Serialize to a string (via a handle)
34 4 ▶ if ( Params::Util::_SCALAR0($_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Params::Util::_SCALAR0($_[0])) 1 3 4
35 1 my $handle = IO::String->new($_[0]);
36 1 return print $handle YAML::Syck::Dump($self);
37 }
38  
39 # Serialize to a generic handle
40 3 ▶ if ( Params::Util::_INSTANCE($_[0], 'IO::Handle') or fileno($_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]) 2 1 3
Condition100%3/3
&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]
l!l&&r!l&&!r
111
MC/DC100%2/2
&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]
&Params::Util::_INSTANCE($_[0], "IO::Handle") fileno $_[0]
Truth table100%3/3
A or B
A= &Params::Util::_INSTANCE($_[0], "IO::Handle")B= fileno $_[0]
ABresult
1X1
011
000
41 2 my $handle = $_[0];
42 2 return print $handle YAML::Syck::Dump($self);
43 }
44  
45 # Serialize to a file name (locking it)
46 1 ▶ if ( defined $_[0] and ! ref $_[0] and length $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and not ref $_[0] and length $_[0]) 1 0 1
Condition33%2/6
defined $_[0] and not ref $_[0] and length $_[0]
!ll&&!rl&&r
001
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
001
MC/DC0%0/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] not ref $_[0] length $_[0]
Truth table25%1/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
ABCresult
0XX0
10X0
1100
1111
47 1 my $fh;
48 1 my $mode = '+<';
49 1 ▶ if ( not -e $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $_[0]) 1 0 1
50 1 $mode = '+>';
51 }
52 1 ▶ if ( not open($fh, $mode, $_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, $mode, $_[0]) 0 1 1
53 0 return undef;
54 }
55 1 ▶ if ( not flock($fh, LOCK_EX) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (flock $fh, 2) 0 1 1
56 0 return undef;
57 }
58 1 ▶ if ( not truncate($fh, 0) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (truncate $fh, 0) 0 1 1
59 0 return undef;
60 }
61 1 ▶ if ( not print $fh YAML::Syck::Dump($self) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (print $fh YAML::Syck::Dump($self)) 0 1 1
62 0 return undef;
63 }
64 1 ▶ if ( not close $fh ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (close $fh) 0 1 1
65 0 return undef;
66 }
67 1 return 1;
68 }
69  
70 # We don't support anything else
71 0 undef;
72 }
73  
74 4 ▶sub deserialize {
Subroutine deserialize: called CC=9 SCAR=24.0
Pod documented
75 4 my $class = shift;
76  
77 # Deserialize from a string
78 4 ▶ if ( Params::Util::_SCALAR0($_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Params::Util::_SCALAR0($_[0])) 1 3 4
79 1 return YAML::Syck::Load(${$_[0]});
80 }
81  
82 # Deserialize from a generic handle
83 3 ▶ if ( Params::Util::_INSTANCE($_[0], 'IO::Handle') or fileno($_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]) 2 1 3
Condition100%3/3
&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]
l!l&&r!l&&!r
111
MC/DC100%2/2
&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]
&Params::Util::_INSTANCE($_[0], "IO::Handle") fileno $_[0]
Truth table100%3/3
A or B
A= &Params::Util::_INSTANCE($_[0], "IO::Handle")B= fileno $_[0]
ABresult
1X1
011
000
84 2 my $handle = $_[0];
85 2 return YAML::Syck::Load(join '', <$handle>);
86 }
87  
88 # Deserialize from a file name (locking it)
89 1 ▶ if ( defined $_[0] and ! ref $_[0] and length $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and not ref $_[0] and length $_[0]) 1 0 1
Condition33%2/6
defined $_[0] and not ref $_[0] and length $_[0]
!ll&&!rl&&r
001
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
001
MC/DC0%0/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] not ref $_[0] length $_[0]
Truth table25%1/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
ABCresult
0XX0
10X0
1100
1111
90 1 my $fh;
91 1 ▶ if ( not open($fh, '<', $_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, "<", $_[0]) 0 1 1
92 0 return undef;
93 }
94 1 ▶ if ( not flock($fh, LOCK_SH) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (flock $fh, 1) 0 1 1
95 0 return undef;
96 }
97 1 return YAML::Syck::Load(join '', <$fh>);
98 }
99  
100 # We don't support anything else
101 0 undef;
102 }
103  
104 3 1;
105  
106 __END__
↑ Summary