CAB/Persistent.pm

filter: Statementstmt 19.6% 32 / 163 Branchbran 0.0% 0 / 88 Conditioncond 0.0% 0 / 75 MC/DCmcdc 0.0% 0 / 39 Subroutinesub 28.2% 11 / 39 Podpod 81.4% 22 / 27 totaltotal 15.0% 65 / 431 CC 72 SCAR 39.6
CC
72
Cov
10%
savePerlRef
156.0
loadPerlRef
132.0
loadPerlString
90.0
CRAP 52.3
« CAB/Format/XmlTokWrapFast.pm ↑ Summary CAB/Analyzer/Automaton/Dyn.pm »
1 ## -*- Mode: CPerl -*-
2 ##
3 ## File: DTA::CAB::Persistent.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: abstract class for persistent & configurable objects
6  
7 package DTA::CAB::Persistent;
8 1 ▶use DTA::CAB::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DTA::CAB::Unify;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ##==============================================================================
17 ## Globals
18 ##==============================================================================
19  
20 1 our @ISA = qw(DTA::CAB::Logger);
21  
22 ##==============================================================================
23 ## Constructors etc.
24 ##==============================================================================
25  
26 ## $obj = CLASS_OR_OBJ->new(%args)
27 ## + object structure: (assumed to be HASH ref, other references should be OK
28 ## with appropritate method overrides
29 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
30 0 my $that = shift;
31 0 ▶ return bless {@_}, ref($that)||$that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
32 }
33  
34 ## $obj = $obj->clone()
35 ## + deep clone
36 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
37 #storable_push({Eval=>1,Deparse=>1});
38 0 my $clone = Storable::dclone($_[0]);
39 #storable_pop();
40 0 return $clone;
41 }
42  
43 ## @STORABLE_STACK
44 ## + state variables (HASH-refs) for Storable module
45 1 our @STORABLE_STACK = qw();
46  
47 ## \%vars = CLASS_OR_OBJ->storable_push()
48 ## \%vars = CLASS_OR_OBJ->storable_push(\%vars)
49 ## + pushes old Storable state vars onto @STORABLE_STACK, & sets current \%vars
50 0 ▶sub storable_push {
Subroutine storable_push: not called CC=3 SCAR=18.7
Pod undocumented
51 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
52 0 my $vars = shift;
53 0 ▶ $vars = {Deparse=>1,Eval=>1} if (!$vars);
Branch: 1 branch
BranchTrueFalseTotal
unless $vars 0 0 0
54 0 push(@STORABLE_STACK, {Deparse=>$Storable::Deparse,Eval=>$Storable::Eval});
55 0 ${"Storable::$_"} = $vars->{$_} foreach (keys %$vars);
56 0 return $vars;
57 }
58  
59 ## \%vars = CLASS_OR_OBJ->storable_pop()
60 ## + pops Storable state vars from @STORABLE_STACK
61 0 ▶sub storable_pop {
Subroutine storable_pop: not called CC=3 SCAR=18.1
Pod undocumented
62 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 0 ▶ return if (!@STORABLE_STACK); ##-- nothing to do
Branch: 1 branch
BranchTrueFalseTotal
unless @DTA::CAB::Persistent::STORABLE_STACK 0 0 0
64 0 my $vars = pop(@STORABLE_STACK);
65 0 ${"Storable::$_"} = $vars->{$_} foreach (keys %$vars);
66 0 return $vars;
67 }
68  
69  
70 ##==============================================================================
71 ## Methods: Persistence
72 ##==============================================================================
73  
74 ##======================================================================
75 ## Methods: Persistence: Perl
76  
77 ## @keys = $class_or_obj->noSaveKeys()
78 ## + returns list of keys not to be saved for perl-mode I/O
79 ## + default just returns empty list
80 0 ▶sub noSaveKeys { return qw(); }
Subroutine noSaveKeys: not called CC=1 SCAR=6.9
Pod documented
81  
82 ## $saveRef = $obj->savePerlRef()
83 ## + return reference to be saved
84 ## + default implementation assumes $obj is HASH-ref
85 0 ▶sub savePerlRef {
Subroutine savePerlRef: not called CC=12 SCAR=50.5
Pod documented
86 0 my $obj = shift;
87 0 my %noSave = map {($_=>undef)} $obj->noSaveKeys;
88 return {
89 0 ▶ map { ($_=>(ref($obj->{$_}) && UNIVERSAL::can($obj->{$_},'savePerlRef') ? $obj->{$_}->savePerlRef : $obj->{$_})) }
Branch: 1 branch
BranchTrueFalseTotal
ref $obj->{$_} && UNIVERSAL::can($obj->{$_}, 'savePerlRef') ? : 0 0 0
Condition0%0/3
ref $obj->{$_} and UNIVERSAL::can($obj->{$_}, "savePerlRef")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $obj->{$_} and UNIVERSAL::can($obj->{$_}, "savePerlRef")
ref $obj->{$_} UNIVERSAL::can($obj->{$_}, "savePerlRef")
Truth table0%0/3
A and B
A= ref $obj->{$_}B= UNIVERSAL::can($obj->{$_}, "savePerlRef")
ABresult
0X0
100
111
90 grep {
91 0 (!exists($noSave{$_})
92 && (!ref($obj->{$_})
93 || !UNIVERSAL::isa($obj->{$_},'CODE')
94 || !UNIVERSAL::isa($obj->{$_},'GLOB')
95 || !UNIVERSAL::isa($obj->{$_},'IO::Handle')
96 || !UNIVERSAL::isa($obj->{$_},'Gfsm::Automaton')
97 || !UNIVERSAL::isa($obj->{$_},'Gfsm::Alphabet')
98 || !UNIVERSAL::isa($obj->{$_},'Gfsm::Semiring')
99 || !UNIVERSAL::isa($obj->{$_},'Gfsm::XL::Cascade')
100 0 ▶ || !UNIVERSAL::isa($obj->{$_},'Gfsm::XL::Cascade::Lookup')
Condition0%0/27
exists $noSave{$_} || ref $obj->{$_} && UNIVERSAL::isa($obj->{$_}, 'CODE') && UNIVERSAL::isa($obj->{$_}, 'GLOB') && UNIVERSAL::isa($obj->{$_}, 'IO::Handle') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::Automaton') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::Alphabet') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::Semiring') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::XL::Cascade') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::XL::Cascade::Lookup')
l!l&&r!l&&!r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE") and UNIVERSAL::isa($obj->{$_}, "GLOB") and UNIVERSAL::isa($obj->{$_}, "IO::Handle") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Automaton") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Alphabet") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Semiring") and UNIVERSAL::isa($obj->{$_}, "Gfsm::XL::Cascade") and UNIVERSAL::isa($obj->{$_}, "Gfsm::XL::Cascade::Lookup")
!ll&&!rl&&r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE") and UNIVERSAL::isa($obj->{$_}, "GLOB") and UNIVERSAL::isa($obj->{$_}, "IO::Handle") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Automaton") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Alphabet") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Semiring") and UNIVERSAL::isa($obj->{$_}, "Gfsm::XL::Cascade")
!ll&&!rl&&r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE") and UNIVERSAL::isa($obj->{$_}, "GLOB") and UNIVERSAL::isa($obj->{$_}, "IO::Handle") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Automaton") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Alphabet") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Semiring")
!ll&&!rl&&r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE") and UNIVERSAL::isa($obj->{$_}, "GLOB") and UNIVERSAL::isa($obj->{$_}, "IO::Handle") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Automaton") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Alphabet")
!ll&&!rl&&r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE") and UNIVERSAL::isa($obj->{$_}, "GLOB") and UNIVERSAL::isa($obj->{$_}, "IO::Handle") and UNIVERSAL::isa($obj->{$_}, "Gfsm::Automaton")
!ll&&!rl&&r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE") and UNIVERSAL::isa($obj->{$_}, "GLOB") and UNIVERSAL::isa($obj->{$_}, "IO::Handle")
!ll&&!rl&&r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE") and UNIVERSAL::isa($obj->{$_}, "GLOB")
!ll&&!rl&&r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE")
!ll&&!rl&&r
000
MC/DC0%0/10
exists $noSave{$_} || ref $obj->{$_} && UNIVERSAL::isa($obj->{$_}, 'CODE') && UNIVERSAL::isa($obj->{$_}, 'GLOB') && UNIVERSAL::isa($obj->{$_}, 'IO::Handle') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::Automaton') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::Alphabet') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::Semiring') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::XL::Cascade') && UNIVERSAL::isa($obj->{$_}, 'Gfsm::XL::Cascade::Lookup')
exists $noSave{$_} ref $obj->{$_} UNIVERSAL::isa($obj->{$_}, "CODE") UNIVERSAL::isa($obj->{$_}, "GLOB") UNIVERSAL::isa($obj->{$_}, "IO::Handle") UNIVERSAL::isa($obj->{$_}, "Gfsm::Automaton") UNIVERSAL::isa($obj->{$_}, "Gfsm::Alphabet") UNIVERSAL::isa($obj->{$_}, "Gfsm::Semiring") UNIVERSAL::isa($obj->{$_}, "Gfsm::XL::Cascade") UNIVERSAL::isa($obj->{$_}, "Gfsm::XL::Cascade::Lookup")
Truth table0%0/11
A || B and C and D and E and F and G and H and I and J
A= exists $noSave{$_}B= ref $obj->{$_}C= UNIVERSAL::isa($obj->{$_}, "CODE")D= UNIVERSAL::isa($obj->{$_}, "GLOB")E= UNIVERSAL::isa($obj->{$_}, "IO::Handle")F= UNIVERSAL::isa($obj->{$_}, "Gfsm::Automaton")G= UNIVERSAL::isa($obj->{$_}, "Gfsm::Alphabet")H= UNIVERSAL::isa($obj->{$_}, "Gfsm::Semiring")I= UNIVERSAL::isa($obj->{$_}, "Gfsm::XL::Cascade")J= UNIVERSAL::isa($obj->{$_}, "Gfsm::XL::Cascade::Lookup")
ABCDEFGHIJresult
1XXXXXXXXX1
01111111111
00XXXXXXXX0
010XXXXXXX0
0110XXXXXX0
01110XXXXX0
011110XXXX0
0111110XXX0
01111110XX0
011111110X0
01111111100
101 )
102 )}
103 keys(%$obj)
104 };
105 }
106  
107 ## $loadedObj = $CLASS_OR_OBJ->loadPerlRef($ref)
108 ## + default implementation just clobbers $CLASS_OR_OBJ with $ref and blesses
109 0 ▶sub loadPerlRef {
Subroutine loadPerlRef: not called CC=11 SCAR=48.8
Pod documented
110 0 my ($that,$ref) = @_;
111 0 ▶ if (UNIVERSAL::isa($ref,ref($that)||$that)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($ref, ref $that || $that)) 0 0 0
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
112 ##-- "virtual load": return subclass for superclass method
113 0 ▶ if (ref($that)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $that) { } 0 0 0
114 0 bless($that, ref($ref));
115 } else {
116 0 $that = ref($ref);
117 }
118 }
119 0 ▶ my $obj = ref($that) ? $that : $that->new();
Branch: 1 branch
BranchTrueFalseTotal
ref $that ? : 0 0 0
120 0 $obj = bless(unifyClobber($obj,$ref,undef),ref($obj));
121 0 ▶ if (UNIVERSAL::isa($that,'HASH') && UNIVERSAL::isa($obj,'HASH')) {
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($that, 'HASH') and UNIVERSAL::isa($obj, 'HASH')) { } 0 0 0
elsif (UNIVERSAL::isa($that, 'ARRAY') and UNIVERSAL::isa($obj, 'ARRAY')) { } 0 0 0
elsif (UNIVERSAL::isa($that, 'SCALAR') and UNIVERSAL::isa($obj, 'SCALAR')) { } 0 0 0
Condition0%0/3
UNIVERSAL::isa($that, "HASH") and UNIVERSAL::isa($obj, "HASH")
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($that, "HASH") and UNIVERSAL::isa($obj, "HASH")
UNIVERSAL::isa($that, "HASH") UNIVERSAL::isa($obj, "HASH")
Truth table0%0/3
A and B
A= UNIVERSAL::isa($that, "HASH")B= UNIVERSAL::isa($obj, "HASH")
ABresult
0X0
100
111
122 0 %$that = %$obj; ##-- hack in case someone does "$obj->load()" and expects $obj to be destructively altered...
123 0 return $that;
124 ▶ } elsif (UNIVERSAL::isa($that,'ARRAY') && UNIVERSAL::isa($obj,'ARRAY')) {
Condition0%0/3
UNIVERSAL::isa($that, "ARRAY") and UNIVERSAL::isa($obj, "ARRAY")
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($that, "ARRAY") and UNIVERSAL::isa($obj, "ARRAY")
UNIVERSAL::isa($that, "ARRAY") UNIVERSAL::isa($obj, "ARRAY")
Truth table0%0/3
A and B
A= UNIVERSAL::isa($that, "ARRAY")B= UNIVERSAL::isa($obj, "ARRAY")
ABresult
0X0
100
111
125 0 @$that = @$obj; ##-- ... analagous hack for array refs
126 0 return $that;
127 ▶ } elsif (UNIVERSAL::isa($that,'SCALAR') && UNIVERSAL::isa($obj,'SCALAR')) {
Condition0%0/3
UNIVERSAL::isa($that, "SCALAR") and UNIVERSAL::isa($obj, "SCALAR")
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($that, "SCALAR") and UNIVERSAL::isa($obj, "SCALAR")
UNIVERSAL::isa($that, "SCALAR") UNIVERSAL::isa($obj, "SCALAR")
Truth table0%0/3
A and B
A= UNIVERSAL::isa($that, "SCALAR")B= UNIVERSAL::isa($obj, "SCALAR")
ABresult
0X0
100
111
128 0 $$that = $$obj; ##-- ... analagous hack for scalar refs
129 0 return $that;
130 }
131 0 return $obj;
132 }
133  
134 ##----------------------------------------------------
135 ## Methods: Persistence: Perl: File (delegate to string)
136  
137 ## $rc = $obj->savePerlFile($filename_or_fh, @args)
138 ## + calls "$obj->savePerlString(@args)"
139 0 ▶sub savePerlFile {
Subroutine savePerlFile: not called CC=4 SCAR=30.0
Pod documented
140 0 my ($obj,$file) = (shift,shift);
141 0 ▶ my $fh = ref($file) ? $file : IO::File->new(">$file");
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
142 0 ▶ confess(ref($obj), "::savePerlFile(): open failed for '$file': $!")
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
143 if (!$fh);
144 0 $fh->print("## Perl code auto-generated by ", __PACKAGE__, "::savePerlFile()\n",
145 "## EDIT AT YOUR OWN RISK\n",
146 $obj->savePerlString(@_));
147 0 ▶ $fh->close() if (!ref($file));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $file 0 0 0
148 0 return 1;
149 }
150  
151 ## $obj = $CLASS_OR_OBJ->loadPerlFile($filename_or_fh, %args)
152 ## + calls $CLASS_OR_OBJ->loadPerlString(var=>undef,src=>$filename_or_fh, cabSrcFile=>$file, %args)
153 0 ▶sub loadPerlFile {
Subroutine loadPerlFile: not called CC=5 SCAR=34.0
Pod documented
154 0 my ($that,$file,%args) = @_;
155 0 ▶ my $fh = ref($file) ? $file : IO::File->new("<$file");
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
156 0 ▶ confess((ref($that)||$that), "::loadPerlFile(): open failed for '$file': $!") if (!$fh);
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
157 0 local $/=undef;
158 0 my $str = <$fh>;
159 0 ▶ $fh->close() if (!ref($file));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $file 0 0 0
160 0 return $that->loadPerlString($str, var=>undef, src=>$file, %args);
161 }
162  
163 ##----------------------------------------------------
164 ## Methods: Persistence: Perl: String (perl code)
165  
166 ## $str = $obj->savePerlString(%args)
167 ## + save $obj as perl code
168 ## + %args:
169 ## var => $perl_var_name
170 0 ▶sub savePerlString {
Subroutine savePerlString: not called CC=2 SCAR=17.9
Pod documented
171 0 my ($obj,%args) = @_;
172 0 ▶ my $var = $args{var} ? $args{var} : '$obj';
Branch: 1 branch
BranchTrueFalseTotal
$args{'var'} ? : 0 0 0
173  
174 0 my $ref = $obj->savePerlRef();
175 0 my $dumper = Data::Dumper->new([$ref],[$var]);
176 0 $dumper->Indent(1)->Purity(1)->Terse(0)->Sortkeys(1);
177 0 my $str = join('', $dumper->Dump);
178  
179 0 return $str;
180 }
181  
182 ## $obj = $CLASS_OR_OBJ->loadPerlString($str,%args)
183 ## + %args:
184 ## var=>$perl_var_name, ##-- default='$index' ; local var: $VAR
185 ## src=>$src_name, ##-- default=(substr($str,0,42).'...'); local var: $SRC
186 ## %more_obj_args, ##-- literally inserted into $obj
187 ## + load from perl code string
188 0 ▶sub loadPerlString {
Subroutine loadPerlString: not called CC=9 SCAR=45.0
Pod documented
189 0 my ($that,$str,%args) = @_;
190 0 ▶ my $var = $args{var} ? $args{var} : '$obj';
Branch: 1 branch
BranchTrueFalseTotal
$args{'var'} ? : 0 0 0
191 my $src = (defined($args{src})
192 ? $args{src}
193 0 ▶ : (length($str) <= 42
Branch: 2 branches
BranchTrueFalseTotal
defined $args{'src'} ? : 0 0 0
length $str <= 42 ? : 0 0 0
194 ? $str
195 : (substr($str,0,42).'...')));
196 0 my $VAR = $var;
197 0 ▶ my $SRC = (defined($args{src}) ? $args{src} : '/dev/null');
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'src'} ? : 0 0 0
198 0 my $TOP = $DTA::CAB::Unify::TOP;
199 0 delete(@args{qw(var src)});
200  
201 0 my $loaded = eval("no strict; $str; $var");
202 0 ▶ confess((ref($that)||$that), "::loadString(): eval() failed for '$src': ", $@ ? $@ : $!)
Branch: 2 branches
BranchTrueFalseTotal
if $@ or not defined $loaded 0 0 0
$@ ? : 0 0 0
Condition0%0/6
$@ or not defined $loaded
l!l&&r!l&&!r
000
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not defined $loaded
$@ not defined $loaded
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A or not(B)
A= $@B= not defined $loaded
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
203 if ($@ || !defined($loaded)); #|| $!
204  
205 0 return $that->loadPerlRef($loaded);
206 }
207  
208 ##======================================================================
209 ## Methods: Persistence: Binary
210  
211 ## @keys = $class_or_obj->noSaveBinKeys()
212 ## + returns list of keys not to be saved for binary mode I/O
213 ## + default just returns empty $obj->noSaveKeys()
214 0 ▶sub noSaveBinKeys { return $_[0]->noSaveKeys(); }
Subroutine noSaveBinKeys: not called CC=1 SCAR=6.9
Pod documented
215  
216 ## $binRef = $obj->saveBinRef()
217 ## + return reference to be saved in binary mode
218 ## + default implementation assumes $obj is HASH-ref
219 0 ▶sub saveBinRef {
Subroutine saveBinRef: not called CC=7 SCAR=40.3
Pod documented
220 0 my $obj = shift;
221 0 my %noSave = map {($_=>undef)} $obj->noSaveBinKeys;
222 return
223 bless({
224 0 ▶ map { ($_=>(ref($obj->{$_}) && UNIVERSAL::can($obj->{$_},'saveBinRef') ? $obj->{$_}->saveBinRef() : $obj->{$_})) }
Branch: 1 branch
BranchTrueFalseTotal
ref $obj->{$_} && UNIVERSAL::can($obj->{$_}, 'saveBinRef') ? : 0 0 0
Condition0%0/3
ref $obj->{$_} and UNIVERSAL::can($obj->{$_}, "saveBinRef")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $obj->{$_} and UNIVERSAL::can($obj->{$_}, "saveBinRef")
ref $obj->{$_} UNIVERSAL::can($obj->{$_}, "saveBinRef")
Truth table0%0/3
A and B
A= ref $obj->{$_}B= UNIVERSAL::can($obj->{$_}, "saveBinRef")
ABresult
0X0
100
111
225 grep {
226 0 (!exists($noSave{$_})
227 && (!ref($obj->{$_})
228 || !UNIVERSAL::isa($obj->{$_},'CODE')
229 || !UNIVERSAL::isa($obj->{$_},'GLOB')
230 0 ▶ || !UNIVERSAL::isa($obj->{$_},'IO::Handle')
Condition0%0/12
exists $noSave{$_} || ref $obj->{$_} && UNIVERSAL::isa($obj->{$_}, 'CODE') && UNIVERSAL::isa($obj->{$_}, 'GLOB') && UNIVERSAL::isa($obj->{$_}, 'IO::Handle')
l!l&&r!l&&!r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE") and UNIVERSAL::isa($obj->{$_}, "GLOB") and UNIVERSAL::isa($obj->{$_}, "IO::Handle")
!ll&&!rl&&r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE") and UNIVERSAL::isa($obj->{$_}, "GLOB")
!ll&&!rl&&r
000
ref $obj->{$_} and UNIVERSAL::isa($obj->{$_}, "CODE")
!ll&&!rl&&r
000
MC/DC0%0/5
exists $noSave{$_} || ref $obj->{$_} && UNIVERSAL::isa($obj->{$_}, 'CODE') && UNIVERSAL::isa($obj->{$_}, 'GLOB') && UNIVERSAL::isa($obj->{$_}, 'IO::Handle')
exists $noSave{$_} ref $obj->{$_} UNIVERSAL::isa($obj->{$_}, "CODE") UNIVERSAL::isa($obj->{$_}, "GLOB") UNIVERSAL::isa($obj->{$_}, "IO::Handle")
Truth table0%0/6
A || B and C and D and E
A= exists $noSave{$_}B= ref $obj->{$_}C= UNIVERSAL::isa($obj->{$_}, "CODE")D= UNIVERSAL::isa($obj->{$_}, "GLOB")E= UNIVERSAL::isa($obj->{$_}, "IO::Handle")
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
231 #|| !UNIVERSAL::isa($obj->{$_},'Gfsm::Automaton')
232 #|| !UNIVERSAL::isa($obj->{$_},'Gfsm::Alphabet')
233 #|| !UNIVERSAL::isa($obj->{$_},'Gfsm::Semiring')
234 #|| !UNIVERSAL::isa($obj->{$_},'Gfsm::XL::Cascade')
235 #|| !UNIVERSAL::isa($obj->{$_},'Gfsm::XL::Cascade::Lookup')
236 )
237 )}
238 keys(%$obj)
239 },
240 ref($obj));
241 }
242  
243 ## $loadedObj = $CLASS_OR_OBJ->loadBinRef($ref)
244 ## + default implementation just duplicates default loadPerlRef($ref)
245 0 ▶sub loadBinRef {
Subroutine loadBinRef: not called CC=1 SCAR=6.9
Pod documented
246 0 return DTA::CAB::Persistent::loadPerlRef(@_);
247 }
248  
249 ##----------------------------------------------------
250 ## Methods: Persistence: Bin: File (delegate to FH)
251  
252 ## $rc = $obj->saveBinFile($filename_or_fh, %args)
253 ## + save $obj as binary data to a file or filehandle
254 ## + calls $obj->saveBinFh($fh,%args)
255 0 ▶sub saveBinFile {
Subroutine saveBinFile: not called CC=4 SCAR=30.0
Pod documented
256 0 my ($obj,$file,%args) = @_;
257 0 ▶ my $fh = ref($file) ? $file : IO::File->new(">$file");
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
258 0 ▶ $obj->logconfess("saveBinFile(): open failed for '$file': $!") if (!$fh);
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
259 0 my $rc = $obj->saveBinFh($fh,%args,dst=>$file);
260 0 ▶ $fh->close() if (!ref($file));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $file 0 0 0
261 0 return $rc;
262 }
263  
264 ## $obj = $CLASS_OR_OBJ->loadBinFile($filename_or_fh, %args)
265 ## + load $obj as binary data from a file or filehandle
266 ## + calls $obj->loadBinFh($fh,%args)
267 0 ▶sub loadBinFile {
Subroutine loadBinFile: not called CC=4 SCAR=30.0
Pod documented
268 0 my ($that,$file,%args) = @_;
269 0 ▶ my $fh = ref($file) ? $file : IO::File->new("<$file");
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
270 0 ▶ $that->logconfess("loadBinFile(): open failed for '$file': $!") if (!$fh);
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
271 0 my $rc = $that->loadBinFh($fh,%args,src=>$file);
272 0 ▶ $fh->close() if (!ref($file));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $file 0 0 0
273 0 return $rc;
274 }
275  
276 ##----------------------------------------------------
277 ## Methods: Persistence: Bin: String (delegate to FH)
278  
279 ## $str = $obj->saveBinString(%args)
280 ## + save $obj as binary data using Storable module
281 ## + calls $obj->saveBinFh($fh,%args)
282 0 ▶sub saveBinString {
Subroutine saveBinString: not called CC=3 SCAR=24.8
Pod documented
283 0 my ($obj,%args) = @_;
284 0 my $str = '';
285 0 my $fh = IO::Handle->new();
286 0 ▶ CORE::open($fh,'>',\$str)
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", \$str or $obj->logconfess("saveBinString(): could not open() filehandle for string ref") 0 0 0
287 or $obj->logconfess("saveBinString(): could not open() filehandle for string ref");
288 0 my $rc = $obj->saveBinFh($fh);
289 0 $fh->close();
290 0 ▶ return $rc ? $str : undef;
Branch: 1 branch
BranchTrueFalseTotal
$rc ? : 0 0 0
291 }
292  
293 ## $obj = $CLASS_OR_OBJ->loadBinString( $str, %args)
294 ## $obj = $CLASS_OR_OBJ->loadBinString(\$str, %args)
295 ## + load $obj from Storable binary data string
296 ## + calls $obj->loadBinFh($fh,%args)
297 ## + %args:
298 ## src=>$src_name, ##-- default=(substr($str,0,42).'...')
299 0 ▶sub loadBinString {
Subroutine loadBinString: not called CC=5 SCAR=34.0
Pod documented
300 0 my ($that,$str,%args) = @_;
301 my $src = (defined($args{src})
302 ? $args{src}
303 0 ▶ : (length($str) <= 42
Branch: 2 branches
BranchTrueFalseTotal
defined $args{'src'} ? : 0 0 0
length $str <= 42 ? : 0 0 0
304 ? $str
305 : (substr($str,0,42).'...')));
306  
307 0 my $fh = IO::Handle->new();
308 0 ▶ CORE::open($fh,'<',(ref($str) ? $str : \$str))
Branch: 2 branches
BranchTrueFalseTotal
open $fh, "<", ref $str ? $str : \$str or $that->logconfess("loadBinString(): could not open() filehandle for string ref") 0 0 0
ref $str ? : 0 0 0
309 or $that->logconfess("loadBinString(): could not open() filehandle for string ref");
310 0 my $rc = $that->loadBinFh($fh,src=>$src,%args);
311 0 $fh->close;
312 0 return $rc;
313 }
314  
315 ##----------------------------------------------------
316 ## Methods: Persistence: Bin: FH (guts)
317  
318 ## $obj_or_undef = $obj->saveBinFh($fh,%args)
319 ## + save $obj to binary Storable data handle
320 ## + calls $obj->saveBinRef()
321 ## + %args:
322 ## netorder => $bool, ##-- if true (default), save in network order
323 0 ▶sub saveBinFh {
Subroutine saveBinFh: not called CC=5 SCAR=34.0
Pod documented
324 0 my ($obj,$fh,%args) = @_;
325 0 my $ref = $obj->saveBinRef();
326 0 ▶ if ($args{netorder} || !exists($args{netorder})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"netorder"} or not exists $args{"netorder"}) 0 0 0
Condition0%0/3
$args{"netorder"} or not exists $args{"netorder"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"netorder"} or not exists $args{"netorder"}
$args{"netorder"} not exists $args{"netorder"}
Truth table0%0/3
A or not(B)
A= $args{"netorder"}B= not exists $args{"netorder"}
ABresult
1X1
011
000
327 0 ▶ return Storable::nstore_fd($ref,$fh) ? $obj : undef;
Branch: 1 branch
BranchTrueFalseTotal
Storable::nstore_fd($ref, $fh) ? : 0 0 0
328 }
329 0 ▶ return Storable::store_fd($ref,$fh) ? $obj : undef;
Branch: 1 branch
BranchTrueFalseTotal
Storable::store_fd($ref, $fh) ? : 0 0 0
330 }
331  
332 ## $obj = $CLASS_OR_OBJ->loadBinFh($fh, %args)
333 ## + load $obj from Storable binary data handle
334 ## + calls $obj->loadBinFh($fh,%args)
335 ## + %args:
336 ## src=>$src_name, ##-- default=(substr($str,0,42).'...')
337 0 ▶sub loadBinFh {
Subroutine loadBinFh: not called CC=1 SCAR=6.9
Pod documented
338 0 my ($that,$fh,%args) = @_;
339 0 my $loaded = Storable::retrieve_fd($fh);
340 0 return $that->loadBinRef($loaded);
341 }
342  
343 ##======================================================================
344 ## Methods: Persistence: Generic
345  
346 ##----------------------------------------------------
347 ## Methods: Persistence: Generic: utils
348  
349 ## $mode = $CLASS_OR_OBJ->guessFileMode($filename)
350 0 ▶sub guessFileMode {
Subroutine guessFileMode: not called CC=2 SCAR=17.9
Pod documented
351 0 my ($that,$filename) = @_;
352 0 ▶ return 'bin' if ($filename =~ /\.(?:sto|bin)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $filename =~ /\.(?:sto|bin)$/ 0 0 0
353 0 return 'perl';
354 }
355  
356 ## $rc = $CLASS_OR_OBJ->_io_generic(%args)
357 ## + generic I/O wrapper
358 ## + %args:
359 ## which => $which, ##-- one of: 'load' or 'save' (default)
360 ## mode => $mode, ##-- one of: 'bin' or 'perl' (default: guessFileMode($file))
361 ## type => $type, ##-- one of: 'file', 'fh', or 'string' (default)
362 ## file => $file, ##-- any filename, used to guess mode
363 ## arg0 => $arg0, ##-- first arg to pass to the underlying I/O method (default=none)
364 0 ▶sub _io_generic {
Subroutine _io_generic: not called CC=7 SCAR=40.3
365 0 my ($that,%args) = @_;
366 0 ▶ $args{mode} = $that->guessFileMode($args{file}) if ($args{file} && !$args{mode});
Branch: 1 branch
BranchTrueFalseTotal
if $args{"file"} and not $args{"mode"} 0 0 0
Condition0%0/3
$args{"file"} and not $args{"mode"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"file"} and not $args{"mode"}
$args{"file"} not $args{"mode"}
Truth table0%0/3
A and not(B)
A= $args{"file"}B= not $args{"mode"}
ABresult
0X0
100
111
367 0 ▶ $args{which} = 'save' if (!$args{which});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"which"} 0 0 0
368 0 ▶ $args{type} = 'string' if (!$args{type});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"type"} 0 0 0
369 0 my $subname = $args{which}.ucfirst(lc($args{mode})).ucfirst(lc($args{type}));
370 0 ▶ my $sub = $that->can($subname)
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $that->can($subname) or $that->logconfess("_io_generic(): no method for '${subname}'") 0 0 0
371 or $that->logconfess("_io_generic(): no method for '$subname'");
372 0 ▶ return $sub->($that, (exists($args{arg0}) ? $args{arg0} : qw()), %args);
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'arg0'} ? : 0 0 0
373 }
374  
375 ##----------------------------------------------------
376 ## Methods: Persistence: Generic: save
377  
378 ## $obj_or_undef = $CLASS_OR_OBJ->save(%args)
379 ## + %args: see _io_generic()
380 0 ▶sub save {
Subroutine save: not called CC=1 SCAR=6.9
Pod undocumented
381 0 my ($that,%args) = @_;
382 0 return $that->_io_generic(%args,which=>'save');
383 }
384  
385 ## $obj_or_undef = $CLASS_OR_OBJ->saveFile($filename_or_fh,%args)
386 ## + %args: see _io_generic()
387 0 ▶sub saveFile {
Subroutine saveFile: not called CC=1 SCAR=6.9
Pod documented
388 0 my ($that,$file,%args) = @_;
389 0 return $that->_io_generic(file=>$file,%args,which=>'save',type=>'file',arg0=>$file);
390 }
391 1 ▶BEGIN { *saveFh = \&saveFile; }
Subroutine BEGIN: called CC=1 SCAR=0.0
392  
393 ## $obj_or_undef = $CLASS_OR_OBJ->saveString(%args)
394 ## + %args: see _io_generic()
395 0 ▶sub saveString {
Subroutine saveString: not called CC=1 SCAR=6.9
Pod documented
396 0 my ($that,%args) = @_;
397 0 return $that->_io_generic(%args,which=>'save',type=>'string');
398 }
399  
400 ##----------------------------------------------------
401 ## Methods: Persistence: Generic: load
402  
403 ## $obj_or_undef = $CLASS_OR_OBJ->load(%args)
404 ## + %args: see _io_generic()
405 0 ▶sub load {
Subroutine load: not called CC=1 SCAR=6.9
Pod undocumented
406 0 my ($that,%args) = @_;
407 0 return $that->_io_generic(%args,which=>'load');
408 }
409  
410 ## $obj_or_undef = $CLASS_OR_OBJ->loadFile($filename_or_fh,%args)
411 ## + %args: see _io_generic()
412 0 ▶sub loadFile {
Subroutine loadFile: not called CC=1 SCAR=6.9
Pod documented
413 0 my ($that,$file,%args) = @_;
414 0 return $that->_io_generic(file=>$file,%args,which=>'load',type=>'file',arg0=>$file);
415 }
416 1 ▶BEGIN { *loadFh = \&loadFile; }
Subroutine BEGIN: called CC=1 SCAR=0.0
417  
418 ## $obj_or_undef = $CLASS_OR_OBJ->loadString($string,%args)
419 ## + %args: see _io_generic()
420 0 ▶sub loadString {
Subroutine loadString: not called CC=1 SCAR=6.9
Pod documented
421 0 my ($that,$str,%args) = @_;
422 0 return $that->_io_generic(%args,which=>'load',type=>'string');
423 }
424  
425  
426 1 1; ##-- be happy
427  
428 __END__
« CAB/Format/XmlTokWrapFast.pm ↑ Summary CAB/Analyzer/Automaton/Dyn.pm »