Process/Storable.pm

filter: Statementstmt 97.1% 67 / 69 Branchbran 71.4% 20 / 28 Conditioncond 66.6% 8 / 12 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 86.1% 112 / 130 CC 19 SCAR 17.9
CC
19
Cov
87%
serialize
9.4
_deserialize
9.4
BEGIN
2.0
CRAP 6.0
« Process/Launcher.pm ↑ Summary Process/Delegatable.pm »
1 package Process::Storable;
2  
3 11 ▶use 5.00503;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Storable ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use IO::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use IO::String ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Params::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Process::Serializable ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
14 11 $VERSION = '0.30';
15 11 @ISA = 'Process::Serializable';
16  
17 # Hack IO::String to be a real IO::Handle
18 11 ▶ unless ( IO::String->isa('IO::Handle') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("IO::String"->isa("IO::Handle")) 11 0 11
19 11 @IO::String::ISA = qw{IO::Handle IO::Seekable};
20 }
21 }
22  
23 11 ▶sub serialize {
Subroutine serialize: called CC=9 SCAR=22.4
Pod documented
24 11 my $self = shift;
25  
26 # Serialize to a named file (locking it)
27 11 ▶ if ( defined $_[0] and ! ref $_[0] and length $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and not ref $_[0] and length $_[0]) 1 10 11
Condition66%4/6
defined $_[0] and not ref $_[0] and length $_[0]
!ll&&!rl&&r
1001
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
0101
MC/DC33%1/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] not ref $_[0] length $_[0]
Truth table50%2/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
ABCresult
0XX0
10X0
1100
1111
28 1 return Storable::lock_nstore($self, shift);
29 }
30  
31 # Serialize to a string (via a handle)
32 10 ▶ if ( Params::Util::_SCALAR0($_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Params::Util::_SCALAR0($_[0])) 1 9 10
33 1 my $string = shift;
34 1 $$string = 'pst0' . Storable::nfreeze($self);
35 1 return 1;
36 }
37  
38 # Serialize to a generic handle
39 9 ▶ if ( defined fileno($_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined fileno $_[0]) 8 1 9
40 8 local $/ = undef;
41 8 return Storable::nstore_fd($self, shift);
42 }
43  
44 # Serialize to an IO::Handle object
45 1 ▶ if ( Params::Util::_INSTANCE($_[0], 'IO::Handle') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Params::Util::_INSTANCE($_[0], "IO::Handle")) 1 0 1
46 1 my $string = Storable::nfreeze($self);
47 1 my $iohandle = shift;
48 1 ▶ $iohandle->print( 'pst0' ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$iohandle->print("pst0") or return undef 1 0 1
49 1 ▶ $iohandle->print( $string ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$iohandle->print($string) or return undef 1 0 1
50 1 return 1;
51 }
52  
53 # We don't support anything else
54 0 undef;
55 }
56  
57 11 ▶sub deserialize {
Subroutine deserialize: called CC=2 SCAR=7.0
Pod documented
58 11 my $class = shift;
59 11 my $self = $class->_deserialize(@_);
60  
61 # Integrity check
62 11 ▶ Params::Util::_INSTANCE($self, $class) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
&Params::Util::_INSTANCE($self, $class) or return undef 11 0 11
63  
64 11 $self;
65 }
66  
67 11 ▶sub _deserialize {
Subroutine _deserialize: called CC=9 SCAR=22.4
68 11 my $class = shift;
69  
70 # Serialize from a named file (locking it)
71 11 ▶ if ( defined $_[0] and ! ref $_[0] and length $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and not ref $_[0] and length $_[0]) 4 7 11
Condition66%4/6
defined $_[0] and not ref $_[0] and length $_[0]
!ll&&!rl&&r
704
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
074
MC/DC33%1/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] not ref $_[0] length $_[0]
Truth table50%2/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
ABCresult
0XX0
10X0
1100
1111
72 4 return Storable::lock_retrieve(shift);
73 }
74  
75 # Serialize from a string (via a handle)
76 7 ▶ if ( Params::Util::_SCALAR0($_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Params::Util::_SCALAR0($_[0])) 1 6 7
77 1 my $string = shift;
78  
79 # Remove the magic header if it exists
80 1 ▶ if ( substr($$string, 0, 4) eq 'pst0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($$string, 0, 4) eq "pst0") 1 0 1
81 1 substr($$string, 0, 4, '');
82 }
83  
84 1 return Storable::thaw($$string);
85 }
86  
87 # Serialize from a generic handle
88 6 ▶ if ( defined fileno($_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined fileno $_[0]) 5 1 6
89 5 return Storable::retrieve_fd(shift);
90 }
91  
92 # Serialize from an IO::Handle object
93 1 ▶ if ( Params::Util::_INSTANCE($_[0], 'IO::Handle') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Params::Util::_INSTANCE($_[0], "IO::Handle")) 1 0 1
94 1 local $/ = undef;
95 1 my $string = $_[0]->getline;
96  
97 # Remove the magic header if it exists
98 1 ▶ if ( substr($string, 0, 4) eq 'pst0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($string, 0, 4) eq "pst0") 1 0 1
99 1 substr($string, 0, 4, '');
100 }
101  
102 1 return Storable::thaw($string);
103 }
104  
105 # We don't support anything else
106 0 undef;
107 }
108  
109 11 1;
110  
111 __END__
« Process/Launcher.pm ↑ Summary Process/Delegatable.pm »