blib/lib/FreezeThaw.pm

filter: Statementstmt 92.5% 297 / 321 Branchbran 75.0% 129 / 172 Conditioncond 63.3% 38 / 60 MC/DCmcdc 33.3% 12 / 36 Subroutinesub 80.3% 41 / 51 Podpod 17.2% 5 / 29 totaltotal 78.0% 522 / 669 CC 112 SCAR 27.1
CC
112
Cov
84%
freezeScalar
42.3
thawScalar
21.6
thaw
15.4
CRAP 15.0
↑ Summary
1 =head1 NAME
2  
3 FreezeThaw - converting Perl structures to strings and back.
4  
5 =head1 SYNOPSIS
6  
7 use FreezeThaw qw(freeze thaw cmpStr safeFreeze cmpStrHard);
8 $string = freeze $data1, $data2, $data3;
9 ...
10 ($olddata1, $olddata2, $olddata3) = thaw $string;
11 if (cmpStr($olddata2,$data2) == 0) {print "OK!"}
12  
13 =head1 DESCRIPTION
14  
15 Converts data to/from stringified form, appropriate for
16 saving-to/reading-from permanent storage.
17  
18 Deals with objects, circular lists, repeated appearence of the same
19 refence. Does not deal with overloaded I<stringify> operator yet.
20  
21 =head1 EXPORT
22  
23 =over 12
24  
25 =item Default
26  
27 None.
28  
29 =item Exportable
30  
31 C<freeze thaw cmpStr cmpStrHard safeFreeze>.
32  
33 =back
34  
35 =head1 User API
36  
37 =over 12
38  
39 =item C<cmpStr>
40  
41 analogue of C<cmp> for data. Takes two arguments and compares them as
42 separate entities.
43  
44 =item C<cmpStrHard>
45  
46 analogue of C<cmp> for data. Takes two arguments and compares them
47 considered as a group.
48  
49 =item C<freeze>
50  
51 returns a string that encupsulates its arguments (considered as a
52 group). C<thaw>ing this string leads to a fatal error if arguments to
53 C<freeze> contained references to C<GLOB>s and C<CODE>s.
54  
55 =item C<safeFreeze>
56  
57 returns a string that encupsulates its arguments (considered as a
58 group). The result is C<thaw>able in the same process. C<thaw>ing the
59 result in a different process should result in a fatal error if
60 arguments to C<safeFreeze> contained references to C<GLOB>s and
61 C<CODE>s.
62  
63 =item C<thaw>
64  
65 takes one string argument and returns an array. The elements of the
66 array are "equivalent" to arguments of the C<freeze> command that
67 created the string. Can result in a fatal error (see above).
68  
69 =back
70  
71 =head1 Developer API
72  
73 C<FreezeThaw> C<freeze>s and C<thaw>s data blessed in some package by
74 calling methods C<Freeze> and C<Thaw> in the package. The fallback
75 methods are provided by the C<FreezeThaw> itself. The fallback
76 C<Freeze> freezes the "content" of blessed object (from Perl point of
77 view). The fallback C<Thaw> blesses the C<thaw>ed data back into the package.
78  
79 So the package needs to define its own methods only if the fallback
80 methods will fail (for example, for a lot of data the "content" of an
81 object is an address of some B<C> data). The methods are called like
82  
83 $newcooky = $obj->Freeze($cooky);
84 $obj = Package->Thaw($content,$cooky);
85  
86 To save and restore the data the following method are applicable:
87  
88 $cooky->FreezeScalar($data,$ignorePackage,$noduplicate);
89  
90 during Freeze()ing, and
91  
92 $data = $cooky->ThawScalar;
93  
94 Two optional arguments $ignorePackage and $noduplicate regulate
95 whether the freezing should not call the methods even if $data is a
96 reference to a blessed object, and whether the data should not be
97 marked as seen already even if it was seen before. The default methods
98  
99 sub UNIVERSAL::Freeze {
100 my ($obj, $cooky) = (shift, shift);
101 $cooky->FreezeScalar($obj,1,1);
102 }
103  
104 sub UNIVERSAL::Thaw {
105 my ($package, $cooky) = (shift, shift);
106 my $obj = $cooky->ThawScalar;
107 bless $obj, $package;
108 }
109  
110 call the C<FreezeScalar> method of the $cooky since the freezing
111 engine will see the data the second time during this call. Indeed, it
112 is the freezing engine who calls UNIVERSAL::Freeze(), and it calls it
113 because it needs to freeze $obj. The above call to
114 $cooky->FreezeScalar() handles the same data back to engine, but
115 because flags are different, the code does not cycle.
116  
117 Freezing and thawing $cooky also allows the following additional methods:
118  
119 $cooky->isSafe;
120  
121 to find out whether the current freeze was initiated by C<freeze> or
122 C<safeFreeze> command. Analogous method for thaw $cooky returns
123 whether the current thaw operation is considered safe (i.e., either
124 does not contain cached elsewhere data, or comes from the same
125 application). You can use
126  
127 $cooky->makeSafe;
128  
129 to prohibit cached data for the duration of the rest of freezing or
130 thawing of current object.
131  
132 Two methods
133  
134 $value = $cooky->repeatedOK;
135 $cooky->noRepeated; # Now repeated are prohibited
136  
137 allow to find out/change the current setting for allowing repeated
138 references.
139  
140 If you want to flush the cache of saved objects you can use
141  
142 FreezeThaw->flushCache;
143  
144 this can invalidate some frozen string, so that thawing them will
145 result in fatal error.
146  
147 =head2 Instantiating
148  
149 Sometimes, when an object from a package is recreated in presense of
150 repeated references, it is not safe to recreate the internal structure
151 of an object in one step. In such a situation recreation of an object
152 is carried out in two steps: in the first the object is C<allocate>d,
153 in the second it is C<instantiate>d.
154  
155 The restriction is that during the I<allocation> step you cannot use any
156 reference to any Perl object that can be referenced from any other
157 place. This restriction is applied since that object may not exist yet.
158  
159 Correspondingly, during I<instantiation> step the previosly I<allocated>
160 object should be C<filled>, i.e., it can be changed in any way such
161 that the references to this object remain valid.
162  
163 The methods are called like this:
164  
165 $pre_object_ref = Package->Allocate($pre_pre_object_ref);
166 # Returns reference
167 Package->Instantiate($pre_object_ref,$cooky);
168 # Converts into reference to blessed object
169  
170 The reverse operations are
171  
172 $object_ref->FreezeEmpty($cooky);
173 $object_ref->FreezeInstance($cooky);
174  
175 during these calls object can C<freezeScalar> some information (in a
176 usual way) that will be used during C<Allocate> and C<Instantiate>
177 calls (via C<thawScalar>). Note that the return value of
178 C<FreezeEmpty> is cached during the phase of creation of uninialized
179 objects. This B<must> be used like this: the return value is the
180 reference to the created object, so it is not destructed until other
181 objects are created, thus the frozen values of the different objects
182 will not share the same references. Example of bad result:
183  
184 $o1->FreezeEmpty($cooky)
185  
186 freezes C<{}>, and C<$o2-E<gt>FreezeEmpty($cooky)> makes the same. Now
187 nobody guaranties that that these two copies of C<{}> are different,
188 unless a reference to the first one is preserved during the call to
189 C<$o2-E<gt>FreezeEmpty($cooky)>. If C<$o1-E<gt>FreezeEmpty($cooky)>
190 returns the value of C<{}> it uses, it will be preserved by the
191 engine.
192  
193 The helper function C<FreezeThaw::copyContents> is provided for
194 simplification of instantiation. The syntax is
195  
196 FreezeThaw::copyContents $to, $from;
197  
198 The function copies contents the object $from point to into what the
199 object $to points to (including package for blessed references). Both
200 arguments should be references.
201  
202 The default methods are provided. They do the following:
203  
204 =over 12
205  
206 =item C<FreezeEmpty>
207  
208 Freezes an I<empty> object of underlying type.
209  
210 =item C<FreezeInstance>
211  
212 Calls C<Freeze>.
213  
214 =item C<Allocate>
215  
216 Thaws what was frozen by C<FreezeEmpty>.
217  
218 =item C<Instantiate>
219  
220 Thaws what was frozen by C<FreezeInstance>, uses C<copyContents> to
221 transfer this to the $pre_object.
222  
223 =back
224  
225 =head1 BUGS and LIMITATIONS
226  
227 A lot of objects are blessed in some obscure packages by XSUB
228 typemaps. It is not clear how to (automatically) prevent the
229 C<UNIVERSAL> methods to be called for objects in these packages.
230  
231 The objects which can survive freeze()/thaw() cycle must also survive a
232 change of a "member" to an equal member. Say, after
233  
234 $a = [a => 3];
235 $a->{b} = \ $a->{a};
236  
237 $a satisfies
238  
239 $a->{b} == \ $a->{a}
240  
241 This property will be broken by freeze()/thaw(), but it is also broken by
242  
243 $a->{a} = delete $a->{a};
244  
245 =cut
246  
247 2 require 5.002; # defined ref stuff...
248  
249 # Different line noise chars:
250 #
251 # $567| next 567 chars form a scalar
252 #
253 # @34| next 34 scalars form an array
254 #
255 # %34| next 34 scalars form a hash
256 #
257 # ? next scalar is a safe-stamp at beginning
258 #
259 # ? next scalar is a stringified data
260 #
261 # ! repeated array follows (after a scalar denoting array $#),
262 # (possibly?) followed by instantiation array. At beginning
263 #
264 # <45| ordinal of element in repeated array
265 #
266 # * stringified glob follows
267 #
268 # & stringified coderef follows
269 #
270 # \\ stringified defererenced data follows
271 #
272 # / stringified REx follows
273 #
274 # > stringified package name follows, then frozen data
275 #
276 # { stringified package name follows, then allocation data
277 #
278 # } stringified package name follows, then instantiation data
279 #
280 # _ frozen form of undef
281  
282  
283 package FreezeThaw;
284  
285 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
286  
287 2 @ISA = qw(Exporter);
288 2 $VERSION = '1.00';
289 2 @EXPORT_OK = qw(freeze thaw cmpStr cmpStrHard safeFreeze);
290  
291 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
292 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
293  
294 2 my $lock = (reverse time) ^ $$ ^ \&freezeString; # To distingush processes
295  
296 2 ▶use vars qw( @multiple
Subroutine BEGIN: called CC=1 SCAR=0.0
297 %seen_packages
298 $seen_packages
299 %seen_packages
300 %count
301 %address
302 $string
303 $unsafe
304 $noCache
305 $cooky
306 $secondpass
307 ), # Localized in freeze()
308 qw( $norepeated ), # Localized in freezeScalar()
309 qw( $uninitOK ), # Localized in thawScalar()
310 qw( @uninit ), # Localized in thaw()
311 2 qw($safe); # Localized in safeFreeze()
312  
313 2 ▶BEGIN { # allow optimization away
Subroutine BEGIN: called CC=3 SCAR=12.5
314 2 my $haveIsRex = defined &re::is_regexp;
315 2 ▶ my $RexIsREGEXP = ($haveIsRex and # 'REGEXP' eq ref qr/1/); # First-class REX
Condition33%1/3
$haveIsRex && $] >= 5.011
!ll&&!rl&&r
002
MC/DC0%0/2
$haveIsRex && $] >= 5.011
$haveIsRex $] >= 5.011
Truth table33%1/3
A && B
A= $haveIsRexB= $] >= 5.011
ABresult
0X0
100
111
316 $] >= 5.011); # Code like above requires Scalar::Utils::reftype
317 2 ▶ eval <<EOE or die;
Branch: 1 branch
BranchTrueFalseTotal
eval "sub haveIsRex () {$haveIsRex}\nsub RexIsREGEXP () {$RexIsREGEXP}\n1\n" or die 2 0 2
318 sub haveIsRex () {$haveIsRex}
319 sub RexIsREGEXP () {$RexIsREGEXP}
320 1
321 EOE
322 }
323  
324 2 my (%saved);
325  
326 6 ▶my %Empty = ( ARRAY => sub {[]}, HASH => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
327 0 ▶ SCALAR => sub {my $undef; \$undef},
Subroutine __ANON__: not called CC=1 SCAR=6.9
328 8 ▶ REF => sub {my $undef; \$undef},
Subroutine __ANON__: called CC=1 SCAR=0.0
329 CODE => 1, # 1 means atomic
330 GLOB => 1,
331 (RexIsREGEXP
332 1 ▶ ? (Regexp => sub {my $qr = qr//})
Subroutine __ANON__: called CC=1 SCAR=0.0
333 2 : (Regexp => 0)),
334 );
335  
336 # This should better be done via pos() and \G, but apparently \G is not
337 # optimized (bug in the REx optimizer???)
338 2 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=14.5
339 2 my $pointer_size = length pack 'p', 0;
340 #my $max_dig0 = 3*$pointer_size; # 8bits take less than 3 decimals
341 # Now calculate the exact value:
342 #my $max_pointer = sprintf "%.${max_dig0}g", 0x100**$pointer_size;
343 2 my $max_pointer = sprintf "%.0f", 0x100**$pointer_size;
344 2 ▶ die "Panic" if $max_pointer =~ /\D/;
Branch: 1 branch
BranchTrueFalseTotal
if $max_pointer =~ /\D/ 0 2 2
345 2 my $max_pointer_l = length $max_pointer;
346 2 ▶ warn "Max pointer_l=$max_pointer_l" if $ENV{FREEZE_THAW_WARN};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"FREEZE_THAW_WARN"} 0 2 2
347 2 ▶ eval "sub max_strlen_l () {$max_pointer_l}; 1" or die;
Branch: 1 branch
BranchTrueFalseTotal
eval "sub max_strlen_l () {$max_pointer_l}; 1" or die 2 0 2
348 }
349  
350 0 ▶sub flushCache {$lock ^= rand; undef %saved;}
Subroutine flushCache: not called CC=1 SCAR=6.9
Pod undocumented
351  
352 27 ▶sub getref ($) {
Subroutine getref: called CC=5 SCAR=16.7
Pod undocumented
353 27 my $ref = ref $_[0];
354 27 ▶ return $ref if not $ref or defined $Empty{$ref}; # Optimization _and_ Regexp
Branch: 1 branch
BranchTrueFalseTotal
if not $ref or defined $Empty{$ref} 8 19 27
Condition66%2/3
not $ref or defined $Empty{$ref}
l!l&&r!l&&!r
0819
MC/DC50%1/2
not $ref or defined $Empty{$ref}
not $ref defined $Empty{$ref}
Truth table66%2/3
not(A) or B
A= not $refB= defined $Empty{$ref}
ABresult
1X1
011
000
355 19 my $str;
356 19 ▶ if (defined &overload::StrVal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &overload::StrVal) { } 19 0 19
357 19 $str = overload::StrVal($_[0]);
358 } else {
359 0 $str = "$_[0]";
360 }
361 19 ▶ $ref = $1 if $str =~ /=(\w+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /=(\w+)/ 19 0 19
362 19 $ref;
363 }
364  
365 643 ▶sub freezeString {$string .= "\$" . length($_[0]) . '|' . $_[0]}
Subroutine freezeString: called CC=1 SCAR=0.0
Pod undocumented
366  
367 65 ▶sub freezeNumber {$string .= $_[0] . '|'}
Subroutine freezeNumber: called CC=1 SCAR=0.0
Pod undocumented
368  
369 3 ▶sub freezeREx {$string .= '/' . length($_[0]) . '|' . $_[0]}
Subroutine freezeREx: called CC=1 SCAR=0.0
Pod undocumented
370  
371 116 ▶sub thawString { # Returns list: a string and offset of rest
Subroutine thawString: called CC=3 SCAR=11.7
Pod undocumented
372 116 ▶ substr($string, $_[0], 2+max_strlen_l) =~ /^\$(\d+)\|/
Branch: 1 branch
BranchTrueFalseTotal
substr($FreezeThaw::string, $_[0], 22) =~ /^\$(\d+)\|/ or confess('Wrong format of frozen string: ' . substr($FreezeThaw::string, $_[0])) 116 0 116
373 or confess "Wrong format of frozen string: " . substr($string, $_[0]);
374 116 ▶ length($string) - $_[0] > length($1) + 1 + $1
Branch: 1 branch
BranchTrueFalseTotal
length($FreezeThaw::string) - $_[0] > length($1) + 1 + $1 or confess('Frozen string too short: `' . substr($FreezeThaw::string, $_[0]) . q[', expect ] . (length($1) + 2 + $1)) 116 0 116
375 or confess "Frozen string too short: `" .
376 substr($string, $_[0]) . "', expect " . (length($1) + 2 + $1);
377 116 (substr($string, $_[0] + length($1) + 2, $1), $_[0] + length($1) + 2 + $1);
378 }
379  
380 59 ▶sub thawNumber { # Returns list: a number and offset of rest
Subroutine thawNumber: called CC=2 SCAR=7.2
Pod undocumented
381 59 ▶ substr($string, $_[0], 1+max_strlen_l) =~ /^(\d+)\|/
Branch: 1 branch
BranchTrueFalseTotal
substr($FreezeThaw::string, $_[0], 21) =~ /^(\d+)\|/ or confess('Wrong format of frozen string: ' . substr($FreezeThaw::string, $_[0])) 59 0 59
382 or confess "Wrong format of frozen string: " . substr($string, $_[0]);
383 59 ($1, $_[0] + length($1) + 1);
384 }
385  
386 sub _2rex ($);
387 2 ▶if (eval 'ref qr/1/') {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'ref qr/1/') { } 2 0 2
388 2 ▶ eval 'sub _2rex ($) {my $r = shift; qr/$r/} 1' or die;
Subroutine _2rex: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
eval "sub _2rex (\$) {my \$r = shift; qr/\$r/} 1" or die 2 0 2
389 } else {
390 0 ▶ eval 'sub _2rex ($) { shift } 1' or die;
Branch: 1 branch
BranchTrueFalseTotal
eval "sub _2rex (\$) { shift } 1" or die 0 0 0
391 }
392  
393 2 ▶sub thawREx { # Returns list: a REx and offset of rest
Subroutine thawREx: called CC=3 SCAR=11.7
Pod undocumented
394 2 ▶ substr($string, $_[0], 2+max_strlen_l) =~ m,^/(\d+)\|,
Branch: 1 branch
BranchTrueFalseTotal
substr($FreezeThaw::string, $_[0], 22) =~ m[^/(\d+)\|] or confess('Wrong format of frozen REx: ' . substr($FreezeThaw::string, $_[0])) 2 0 2
395 or confess "Wrong format of frozen REx: " . substr($string, $_[0]);
396 2 ▶ length($string) - $_[0] > length($1) + 1 + $1
Branch: 1 branch
BranchTrueFalseTotal
length($FreezeThaw::string) - $_[0] > length($1) + 1 + $1 or confess('Frozen string too short: `' . substr($FreezeThaw::string, $_[0]) . q[', expect ] . (length($1) + 2 + $1)) 2 0 2
397 or confess "Frozen string too short: `" .
398 substr($string, $_[0]) . "', expect " . (length($1) + 2 + $1);
399 2 (_2rex substr($string, $_[0] + length($1) + 2, $1),
400 $_[0] + length($1) + 2 + $1);
401 }
402  
403 314 ▶sub freezeArray {
Subroutine freezeArray: called CC=2 SCAR=6.9
Pod undocumented
404 314 $string .= '@' . @{$_[0]} . '|';
405 314 for (@{$_[0]}) {
406 828 freezeScalar($_);
407 }
408 }
409  
410 84 ▶sub thawArray {
Subroutine thawArray: called CC=5 SCAR=16.3
Pod undocumented
411 84 ▶ substr($string, $_[0], 2+max_strlen_l) =~ /^[\@%](\d+)\|/ # % To make it possible thaw hashes
Branch: 1 branch
BranchTrueFalseTotal
substr($FreezeThaw::string, $_[0], 22) =~ /^[\@%](\d+)\|/ or confess("Wrong format of frozen array: \n$_[0]") 84 0 84
412 or confess "Wrong format of frozen array: \n$_[0]";
413 84 my $count = $1;
414 84 my $off = $_[0] + 2 + length $count;
415 84 my (@res, $res);
416 84 ▶ while ($count and length $string > $off) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count and length $FreezeThaw::string > $off) 174 84 258
Condition66%2/3
$count and length $FreezeThaw::string > $off
!ll&&!rl&&r
840174
MC/DC50%1/2
$count and length $FreezeThaw::string > $off
$count length $FreezeThaw::string > $off
Truth table66%2/3
A and B
A= $countB= length $FreezeThaw::string > $off
ABresult
0X0
100
111
417 174 ($res,$off) = thawScalar($off);
418 174 push(@res,$res);
419 174 --$count;
420 }
421 84 ▶ confess "Wrong length of data in thawing Array: $count left" if $count;
Branch: 1 branch
BranchTrueFalseTotal
if $count 0 84 84
422 84 (\@res, $off);
423 }
424  
425 89 ▶sub freezeHash {
Subroutine freezeHash: called CC=2 SCAR=6.9
Pod undocumented
426 89 my @arr = sort keys %{$_[0]};
427 89 $string .= '%' . (2*@arr) . '|';
428 89 for (@arr, @{$_[0]}{@arr}) {
429 190 freezeScalar($_);
430 }
431 }
432  
433 22 ▶sub thawHash {
Subroutine thawHash: called CC=2 SCAR=6.9
Pod undocumented
434 22 my ($arr, $rest) = &thawArray;
435 22 my %hash;
436 22 my $l = @$arr/2;
437 22 foreach (0 .. $l - 1) {
438 17 $hash{$arr->[$_]} = $arr->[$l + $_];
439 }
440 22 (\%hash,$rest);
441 }
442  
443 # Second optional argument: ignore the package
444 # Third optional one: do not check for duplicates on outer level
445  
446 1242 ▶sub freezeScalar {
Subroutine freezeScalar: called CC=34 SCAR=37.4
Pod undocumented
447 1242 ▶ $string .= '_', return unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 30 1212 1242
448 1212 ▶ return &freezeString unless ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 634 578 1212
449 578 my $ref = ref $_[0];
450 578 my $str;
451 578 ▶ if ($_[1] and $ref) { # Similar to getref()
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] and $ref) { } 35 543 578
Condition66%2/3
$_[1] and $ref
!ll&&!rl&&r
543035
MC/DC50%1/2
$_[1] and $ref
$_[1] $ref
Truth table66%2/3
A and B
A= $_[1]B= $ref
ABresult
0X0
100
111
452 35 ▶ if (defined &overload::StrVal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &overload::StrVal) { } 35 0 35
453 35 $str = overload::StrVal($_[0]);
454 } else {
455 0 $str = "$_[0]";
456 }
457 35 ▶ $ref = $1 if $str =~ /=(\w+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /=(\w+)/ 33 2 35
458 } else {
459 543 $str = "$_[0]";
460 }
461 # Die if a) repeated prohibited, b) met, c) not explicitely requested to ingore.
462 confess "Repeated reference met when prohibited"
463 578 ▶ if $norepeated && !$_[2] && defined $count{$str};
Branch: 1 branch
BranchTrueFalseTotal
if $FreezeThaw::norepeated and not $_[2] and defined $FreezeThaw::count{$str} 0 578 578
Condition33%2/6
$FreezeThaw::norepeated and not $_[2] and defined $FreezeThaw::count{$str}
!ll&&!rl&&r
57800
$FreezeThaw::norepeated and not $_[2]
!ll&&!rl&&r
57800
MC/DC0%0/3
$FreezeThaw::norepeated and not $_[2] and defined $FreezeThaw::count{$str}
$FreezeThaw::norepeated not $_[2] defined $FreezeThaw::count{$str}
Truth table25%1/4
A and not(B) and C
A= $FreezeThaw::norepeatedB= not $_[2]C= defined $FreezeThaw::count{$str}
ABCresult
0XX0
10X0
1100
1111
464 578 ▶ if ($secondpass and !$_[2]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($FreezeThaw::secondpass and not $_[2]) { } 106 472 578
elsif (not $_[2]) { } 418 54 472
Condition100%3/3
$FreezeThaw::secondpass and not $_[2]
!ll&&!rl&&r
44131106
MC/DC100%2/2
$FreezeThaw::secondpass and not $_[2]
$FreezeThaw::secondpass not $_[2]
Truth table100%3/3
A and not(B)
A= $FreezeThaw::secondpassB= not $_[2]
ABresult
0X0
100
111
465 $string .= "<$address{$str}|", return
466 106 ▶ if defined $count{$str} and $count{$str} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $FreezeThaw::count{$str} and $FreezeThaw::count{$str} > 1 65 41 106
Condition66%2/3
defined $FreezeThaw::count{$str} and $FreezeThaw::count{$str} > 1
!ll&&!rl&&r
04165
MC/DC50%1/2
defined $FreezeThaw::count{$str} and $FreezeThaw::count{$str} > 1
defined $FreezeThaw::count{$str} $FreezeThaw::count{$str} > 1
Truth table66%2/3
A and B
A= defined $FreezeThaw::count{$str}B= $FreezeThaw::count{$str} > 1
ABresult
0X0
100
111
467 } elsif (!$_[2]) {
468 # $count{$str} is defined if we have seen it on this pass.
469 $address{$str} = @multiple, push(@multiple, $_[0])
470 418 ▶ if defined $count{$str} and not exists $address{$str};
Branch: 1 branch
BranchTrueFalseTotal
if defined $FreezeThaw::count{$str} and not exists $FreezeThaw::address{$str} 34 384 418
Condition100%3/3
defined $FreezeThaw::count{$str} and not exists $FreezeThaw::address{$str}
!ll&&!rl&&r
376834
MC/DC100%2/2
defined $FreezeThaw::count{$str} and not exists $FreezeThaw::address{$str}
defined $FreezeThaw::count{$str} not exists $FreezeThaw::address{$str}
Truth table100%3/3
A and not(B)
A= defined $FreezeThaw::count{$str}B= not exists $FreezeThaw::address{$str}
ABresult
0X0
100
111
471 # This is for debugging and shortening thrown-away output (also
472 # internal data in arrays and hashes is not duplicated).
473 $string .= "<$address{$str}|", ++$count{$str}, return
474 418 ▶ if defined $count{$str};
Branch: 1 branch
BranchTrueFalseTotal
if defined $FreezeThaw::count{$str} 42 376 418
475 376 ++$count{$str};
476 }
477 471 ▶ return &freezeArray if $ref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "ARRAY" 308 163 471
478 163 ▶ return &freezeHash if $ref eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "HASH" 89 74 163
479 return &freezeREx if haveIsRex ? re::is_regexp($_[0])
480 74 ▶ : ($ref eq 'Regexp' and not defined ${$_[0]});
Branch: 1 branch
BranchTrueFalseTotal
if &re::is_regexp($_[0]) 3 71 74
481 71 ▶ $string .= "*", return &freezeString
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "GLOB" and not $FreezeThaw::safe 0 71 71
Condition66%2/3
$ref eq "GLOB" and not $FreezeThaw::safe
!ll&&!rl&&r
6830
MC/DC0%0/2
$ref eq "GLOB" and not $FreezeThaw::safe
$ref eq "GLOB" not $FreezeThaw::safe
Truth table66%2/3
A and not(B)
A= $ref eq "GLOB"B= not $FreezeThaw::safe
ABresult
0X0
100
111
482 if $ref eq 'GLOB' and !$safe;
483 71 ▶ $string .= "&", return &freezeString
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "CODE" and not $FreezeThaw::safe 0 71 71
Condition66%2/3
$ref eq "CODE" and not $FreezeThaw::safe
!ll&&!rl&&r
6650
MC/DC0%0/2
$ref eq "CODE" and not $FreezeThaw::safe
$ref eq "CODE" not $FreezeThaw::safe
Truth table66%2/3
A and not(B)
A= $ref eq "CODE"B= not $FreezeThaw::safe
ABresult
0X0
100
111
484 if $ref eq 'CODE' and !$safe;
485 71 ▶ $string .= '\\', return &freezeScalar( $ {shift()} )
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "REF" or $ref eq "SCALAR" 42 29 71
Condition100%3/3
$ref eq "REF" or $ref eq "SCALAR"
l!l&&r!l&&!r
321029
MC/DC100%2/2
$ref eq "REF" or $ref eq "SCALAR"
$ref eq "REF" $ref eq "SCALAR"
Truth table100%3/3
A or B
A= $ref eq "REF"B= $ref eq "SCALAR"
ABresult
1X1
011
000
486 if $ref eq 'REF' or $ref eq 'SCALAR';
487 29 ▶ if ($noCache and (($ref eq 'CODE') or $ref eq 'GLOB')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FreezeThaw::noCache and $ref eq "CODE" || $ref eq "GLOB") 0 29 29
Condition16%1/6
$FreezeThaw::noCache and $ref eq "CODE" || $ref eq "GLOB"
!ll&&!rl&&r
2900
$ref eq "CODE" or $ref eq "GLOB"
l!l&&r!l&&!r
000
MC/DC0%0/3
$FreezeThaw::noCache and $ref eq "CODE" || $ref eq "GLOB"
$FreezeThaw::noCache $ref eq "CODE" $ref eq "GLOB"
Truth table25%1/4
A and B or C
A= $FreezeThaw::noCacheB= $ref eq "CODE"C= $ref eq "GLOB"
ABCresult
0XX0
1000
11X1
1011
488 0 confess "CODE and GLOB references prohibited now";
489 }
490 29 ▶ if ($safe and (($ref eq 'CODE') or $ref eq 'GLOB')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FreezeThaw::safe and $ref eq "CODE" || $ref eq "GLOB") 8 21 29
Condition66%4/6
$FreezeThaw::safe and $ref eq "CODE" || $ref eq "GLOB"
!ll&&!rl&&r
2108
$ref eq "CODE" or $ref eq "GLOB"
l!l&&r!l&&!r
530
MC/DC33%1/3
$FreezeThaw::safe and $ref eq "CODE" || $ref eq "GLOB"
$FreezeThaw::safe $ref eq "CODE" $ref eq "GLOB"
Truth table75%3/4
A and B or C
A= $FreezeThaw::safeB= $ref eq "CODE"C= $ref eq "GLOB"
ABCresult
0XX0
1000
11X1
1011
491 8 $unsafe = 1;
492 8 ▶ $saved{$str} = $_[0] unless defined $saved{$str};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $saved{$str} 3 5 8
493 8 $string .= "?";
494 8 return &freezeString;
495 }
496 21 $string .= '>';
497 21 local $norepeated = $norepeated;
498 21 local $noCache = $noCache;
499 21 freezePackage(ref $_[0]);
500 21 $_[0]->Freeze($cooky);
501 }
502  
503 45 ▶sub freezePackage {
Subroutine freezePackage: called CC=2 SCAR=6.9
Pod undocumented
504 45 my $packageid = $seen_packages{$_[0]};
505 45 ▶ if (defined $packageid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packageid) { } 22 23 45
506 22 $string .= ')';
507 22 &freezeNumber( $packageid );
508 } else {
509 23 $string .= '>';
510 23 &freezeNumber( $seen_packages );
511 23 &freezeScalar( $_[0] );
512 23 $seen_packages{ $_[0] } = $seen_packages++;
513 }
514 }
515  
516 19 ▶sub thawPackage { # First argument: offset
Subroutine thawPackage: called CC=2 SCAR=6.9
Pod undocumented
517 19 my $key = substr($string,$_[0],1);
518 19 my ($get, $rest, $id);
519 19 ($id, $rest) = &thawNumber($_[0] + 1);
520 19 ▶ if ($key eq ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq ')') { } 10 9 19
521 10 $get = $seen_packages{$id};
522 } else {
523 9 ($get, $rest) = &thawString($rest);
524 9 $seen_packages{$id} = $get;
525 }
526 19 ($get, $rest);
527 }
528  
529 # First argument: offset; Optional other: index in the @uninit array
530  
531 252 ▶sub thawScalar {
Subroutine thawScalar: called CC=20 SCAR=30.7
Pod undocumented
532 252 my $key = substr($string,$_[0],1);
533 252 ▶ if ($key eq "\$") {&thawString}
Branch: 11 branches
BranchTrueFalseTotal
if ($key eq '$') { } 105 147 252
elsif ($key eq '@') { } 59 88 147
elsif ($key eq '%') { } 22 66 88
elsif ($key eq '/') { } 2 64 66
elsif ($key eq '\\') { } 6 58 64
elsif ($key eq '_') { } 3 55 58
elsif ($key eq '&') { } 0 55 55
elsif ($key eq '*') { } 0 55 55
elsif ($key eq '?') { } 5 50 55
elsif ($key eq '<') { } 31 19 50
elsif ($key eq '>' or $key eq '{' or $key eq '}') { } 19 0 19
534 59 elsif ($key eq '@') {&thawArray}
535 22 elsif ($key eq '%') {&thawHash}
536 2 elsif ($key eq '/') {&thawREx}
537 elsif ($key eq '\\') {
538 6 my ($out,$rest) = &thawScalar( $_[0]+1 ) ;
539 6 (\$out,$rest);
540 }
541 3 elsif ($key eq '_') { (undef, $_[0]+1) }
542 0 elsif ($key eq '&') {confess "Do not know how to thaw CODE"}
543 0 elsif ($key eq '*') {confess "Do not know how to thaw GLOB"}
544 elsif ($key eq '?') {
545 5 my ($address,$rest) = &thawScalar( $_[0]+1 ) ;
546 5 ▶ confess "The saved data accessed in unprotected thaw" unless $unsafe;
Branch: 1 branch
BranchTrueFalseTotal
unless $FreezeThaw::unsafe 0 5 5
547 confess "The saved data disappeared somewhere"
548 5 ▶ unless defined $saved{$address};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $saved{$address} 0 5 5
549 5 ($saved{$address},$rest);
550 } elsif ($key eq '<') {
551 31 ▶ confess "Repeated data prohibited at this moment" unless $uninitOK;
Branch: 1 branch
BranchTrueFalseTotal
unless $FreezeThaw::uninitOK 0 31 31
552 31 my ($off,$end) = &thawNumber ($_[0]+1);
553 31 ($uninit[$off],$end);
554 ▶ } elsif ($key eq '>' or $key eq '{' or $key eq '}') {
Condition83%5/6
$key eq ">" or $key eq "{" or $key eq "}"
l!l&&r!l&&!r
1270
$key eq ">" or $key eq "{"
l!l&&r!l&&!r
577
MC/DC0%0/3
$key eq ">" or $key eq "{" or $key eq "}"
$key eq ">" $key eq "{" $key eq "}"
Truth table75%3/4
A or B or C
A= $key eq ">"B= $key eq "{"C= $key eq "}"
ABCresult
1XX1
01X1
0011
0000
555 19 my ($package,$rest) = &thawPackage( $_[0]+1 );
556 19 my $cooky = bless \$rest, 'FreezeThaw::TCooky';
557 19 local $uninitOK = $uninitOK;
558 19 local $unsafe = $unsafe;
559 19 ▶ if ($key eq '{') {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq '{') { } 7 12 19
elsif ($key eq '}') { } 7 5 12
560 7 my $res = $package->Allocate($cooky);
561 7 ($res, $rest);
562 } elsif ($key eq '}') {
563 7 ▶ warn "Here it is undef!" unless defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 7 7
564 7 $package->Instantiate($uninit[$_[1]],$cooky);
565 7 (undef, $rest);
566 } else {
567 5 ($package->Thaw($cooky),$rest);
568 }
569 } else {
570 0 confess "Do not know how to thaw data with code `$key'";
571 }
572 }
573  
574 31 ▶sub freezeEmpty { # Takes a type, freezes ref to empty object
Subroutine freezeEmpty: called CC=3 SCAR=11.0
Pod undocumented
575 31 my $e = $Empty{ref $_[0]};
576 31 ▶ if (ref $e) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $e) { } 17 14 31
elsif ($e) { } 2 12 14
577 17 my $cache = &$e;
578 17 freezeScalar $cache;
579 17 $cache;
580 } elsif ($e) {
581 2 my $cache = shift;
582 2 freezeScalar($cache,1,1); # Atomic
583 2 $cache;
584 } else {
585 12 $string .= "{";
586 12 freezePackage ref $_[0];
587 12 $_[0]->FreezeEmpty($cooky);
588 }
589 }
590  
591 39 ▶sub freeze {
Subroutine freeze: called CC=6 SCAR=17.9
Pod documented
592 39 local @multiple;
593 39 local %seen_packages;
594 39 local $seen_packages = 0;
595 39 local %seen_packages;
596 # local @seentypes;
597 39 local %count;
598 39 local %address;
599 39 local $string = 'FrT;';
600 39 local $unsafe;
601 39 local $noCache;
602 39 local $cooky = bless \$cooky, 'FreezeThaw::FCooky'; # Just something fake
603 39 local $secondpass;
604 39 freezeScalar(\@_);
605 39 ▶ if (@multiple) {
Branch: 1 branch
BranchTrueFalseTotal
if (@FreezeThaw::multiple) 20 19 39
606 # Now repeated structures are enumerated with order of *second* time
607 # they appear in the what we freeze.
608 # What we want is to have them enumerated with respect to the first time
609 #### $string = ''; # Start again
610 #### @multiple = ();
611 #### %address = ();
612 #### for (keys %count) {
613 #### $count{$_} = undef if $count{$_} <= 1; # As at start
614 #### $count{$_} = 0 if $count{$_}; # As at start
615 #### }
616 #### $seen_packages = 0;
617 #### %seen_packages = ();
618 #### freezeScalar(\@_);
619 # Now repeated structures are enumerated with order of first time
620 # they appear in the what we freeze
621 #### my $oldstring = substr $string, 4;
622 20 $string = 'FrT;!'; # Start again
623 20 $seen_packages = 0;
624 20 %seen_packages = (); # XXXX We reshuffle parts of the
625 # string, so the order of packages may
626 # be wrong...
627 20 freezeNumber($#multiple);
628 {
629 20 my @cache; # Force different values for different
630 # empty objects.
631 20 foreach (@multiple) {
632 31 push @cache, freezeEmpty $_;
633 }
634 }
635 # for (keys %count) {
636 # $count{$_} = undef
637 # if !(defined $count{$_}) or $count{$_} <= 1; # As at start
638 # }
639 # $string .= '@' . @multiple . '|';
640 20 $secondpass = 1;
641 20 for (@multiple) {
642 31 ▶ freezeScalar($_,0,1,1), next if $Empty{ref $_};
Branch: 1 branch
BranchTrueFalseTotal
if $Empty{ref $_} 19 12 31
643 12 $string .= "}";
644 12 freezePackage ref $_;
645 12 $_->FreezeInstance($cooky);
646 }
647 #### $string .= $oldstring;
648 20 freezeScalar(\@_);
649 }
650 39 ▶ return "FrT;?\$" . length($lock) . "|" . $lock . substr $string, 4
Branch: 1 branch
BranchTrueFalseTotal
if $FreezeThaw::unsafe 3 36 39
651 if $unsafe;
652 36 $string;
653 }
654  
655 3 ▶sub safeFreeze {
Subroutine safeFreeze: called CC=1 SCAR=0.0
Pod documented
656 3 local $safe = 1;
657 3 &freeze;
658 }
659  
660 15 ▶sub copyContents { # Given two references, copies contents of the
Subroutine copyContents: called CC=9 SCAR=22.2
Pod undocumented
661 # second one to the first one, provided they have
662 # the same basic type. The package is copied too.
663 15 my($first,$second) = @_;
664 15 my $ref = getref $second;
665 15 ▶ if ($ref eq 'SCALAR' or $ref eq 'REF') {
Branch: 5 branches
BranchTrueFalseTotal
if ($ref eq 'SCALAR' or $ref eq 'REF') { } 1 14 15
elsif ($ref eq 'ARRAY') { } 4 10 14
elsif ($ref eq 'HASH') { } 7 3 10
elsif (&re::is_regexp($second)) { } 1 2 3
elsif ($ref eq 'CODE' or $ref eq 'GLOB') { } 2 0 2
Condition66%2/3
$ref eq "SCALAR" or $ref eq "REF"
l!l&&r!l&&!r
0114
MC/DC50%1/2
$ref eq "SCALAR" or $ref eq "REF"
$ref eq "SCALAR" $ref eq "REF"
Truth table66%2/3
A or B
A= $ref eq "SCALAR"B= $ref eq "REF"
ABresult
1X1
011
000
666 1 $$first = $$second;
667 } elsif ($ref eq 'ARRAY') {
668 4 @$first = @$second;
669 } elsif ($ref eq 'HASH') {
670 7 %$first = %$second;
671 } elsif (haveIsRex ? re::is_regexp($second)
672 : ($ref eq 'Regexp' and not defined $$second)) {
673 1 $first = qr/$second/;
674 ▶ } elsif ($ref eq 'CODE' or $ref eq 'GLOB') {
Condition66%2/3
$ref eq "CODE" or $ref eq "GLOB"
l!l&&r!l&&!r
110
MC/DC0%0/2
$ref eq "CODE" or $ref eq "GLOB"
$ref eq "CODE" $ref eq "GLOB"
Truth table66%2/3
A or B
A= $ref eq "CODE"B= $ref eq "GLOB"
ABresult
1X1
011
000
675 # Atomic types: already instantiated during allocation pass
676 } else {
677 0 croak "Don't know how to copyContents of type `$ref'";
678 }
679 15 ▶ if (ref $second ne ref $first) { # Rebless
Branch: 1 branch
BranchTrueFalseTotal
if (ref $second ne ref $first) 7 8 15
680 # SvAMAGIC() is a property of a reference, not of a referent!
681 # Thus we cannot use $first here if $second was overloaded...
682 7 bless $_[0], ref $second;
683 }
684 15 $first;
685 }
686  
687 16 ▶sub thaw {
Subroutine thaw: called CC=15 SCAR=27.4
Pod documented
688 16 ▶ confess "thaw requires one argument" unless @_ ==1;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 16 16
689 16 local $string = shift;
690 16 local %seen_packages;
691 16 my $initoff = 0;
692 #print STDERR "Thawing `$string'", substr ($string, 0, 4), "\n";
693 16 ▶ if (substr($string, 0, 4) ne 'FrT;') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($FreezeThaw::string, 0, 4) ne 'FrT;') { } 0 16 16
694 0 ▶ warn "Signature not present, continuing anyway" if $^W;
Branch: 1 branch
BranchTrueFalseTotal
if $^W 0 0 0
695 } else {
696 16 $initoff = 4;
697 }
698 16 ▶ local $unsafe = $initoff + (substr($string, $initoff, 1) eq "?" ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
substr($FreezeThaw::string, $initoff, 1) eq '?' ? : 2 14 16
699 16 ▶ if ($unsafe != $initoff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FreezeThaw::unsafe != $initoff) 2 14 16
700 2 my $key;
701 2 ($key,$unsafe) = thawScalar($unsafe);
702 2 ▶ confess "The lock in frozen data does not match the key"
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq $lock 0 2 2
703 unless $key eq $lock;
704 }
705 16 local @multiple;
706 16 local $uninitOK = 1; # The methods can change it.
707 16 ▶ my $repeated = substr($string,$unsafe,1) eq '!' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
substr($FreezeThaw::string, $FreezeThaw::unsafe, 1) eq '!' ? : 9 7 16
708 16 my ($res, $off);
709 16 ▶ if ($repeated) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repeated) { } 9 7 16
710 9 ($res, $off) = thawNumber($repeated + $unsafe);
711 } else {
712 7 ($res, $off) = thawScalar($repeated + $unsafe);
713 }
714 16 my $cooky = bless \$off, 'FreezeThaw::TCooky';
715 16 ▶ if ($repeated) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repeated) 9 7 16
716 9 local @uninit;
717 9 my $lst = $res;
718 9 foreach (0..$lst) {
719 15 ($res, $off) = thawScalar($off, $_);
720 15 push(@uninit, $res);
721 }
722 9 my @init;
723 9 foreach (0..$lst) {
724 15 ($res, $off) = thawScalar($off, $_);
725 15 push(@init, $res);
726 }
727 #($init, $off) = thawScalar($off);
728 #print "Instantiating...\n";
729 #my $ref;
730 9 for (0..$#uninit) {
731 15 ▶ copyContents $uninit[$_], $init[$_] if ref $init[$_];
Branch: 1 branch
BranchTrueFalseTotal
if ref $init[$_] 8 7 15
732 }
733 9 ($res, $off) = thawScalar($off);
734 }
735 16 ▶ croak "Extra elements in frozen structure: `" . substr($string,$off) . "'"
Branch: 1 branch
BranchTrueFalseTotal
if $off != length $FreezeThaw::string 0 16 16
736 if $off != length $string;
737 16 return @$res;
738 }
739  
740 6 ▶sub cmpStr {
Subroutine cmpStr: called CC=2 SCAR=7.2
Pod documented
741 6 ▶ confess "Compare requires two arguments" unless @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 6 6
742 6 freeze(shift) cmp freeze(shift);
743 }
744  
745 4 ▶sub cmpStrHard {
Subroutine cmpStrHard: called CC=4 SCAR=13.9
Pod documented
746 4 ▶ confess "Compare requires two arguments" unless @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 4 4
747 4 local @multiple;
748 # local @seentypes;
749 4 local %count;
750 4 local %address;
751 4 local $string = 'FrT;';
752 4 local $unsafe;
753 4 local $noCache;
754 4 local $cooky = bless \$cooky, 'FreezeThaw::FCooky'; # Just something fake
755 4 freezeScalar($_[0]);
756 4 my %cnt1 = %count;
757 4 freezeScalar($_[1]);
758 4 my %cnt2 = %count;
759 4 %count = ();
760 # Now all the caches are filled, delete the entries for guys which
761 # are in one argument only.
762 4 my ($elt, $val);
763 4 ▶ while (($elt, $val) = each %cnt1) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %cnt1) 36 4 40
764 36 ▶ $count{$elt}++ if $cnt2{$elt} > $cnt1{$elt};
Branch: 1 branch
BranchTrueFalseTotal
if $cnt2{$elt} > $cnt1{$elt} 1 35 36
765 }
766 4 $string = '';
767 4 freezeScalar($_[0]);
768 4 my $str1 = $string;
769 4 $string = '';
770 4 freezeScalar($_[1]);
771 4 $str1 cmp $string;
772 }
773  
774 # local $string = freeze(shift,shift);
775 # local $uninitOK = 1;
776 # #print "$string\n";
777 # my $off = 7; # Hardwired offset after @2|
778 # if (substr($string,4,1) eq '!') {
779 # $off = 5; # Hardwired offset after !
780 # my ($uninit, $len);
781 # ($len,$off) = thawScalar $off;
782 # local @uninit;
783 # foreach (0..$len) {
784 # ($uninit,$off) = thawScalar $off, $_;
785 # }
786 # $off += 3; # Hardwired offset after @2|
787 # }
788 # croak "Unknown format of frozen array: " . substr($string,$off-3)
789 # unless substr($string,$off-3,1) eq '@';
790 # my ($first,$off2) = thawScalar $off;
791 # my $off3;
792 # ($first,$off3) = thawScalar $off2;
793 # substr($string, $off, $off2-$off) cmp substr($string,$off2,$off3-$off2);
794 # }
795  
796 33 ▶sub FreezeThaw::FCooky::FreezeScalar {
Subroutine FreezeScalar: called CC=1 SCAR=0.0
797 33 shift;
798 33 &freezeScalar;
799 }
800  
801 0 ▶sub FreezeThaw::FCooky::isSafe {
Subroutine isSafe: not called CC=2 SCAR=17.9
802 0 ▶ $safe || $noCache;
Branch: 1 branch
BranchTrueFalseTotal
$FreezeThaw::safe or $FreezeThaw::noCache 0 0 0
803 }
804  
805 0 ▶sub FreezeThaw::FCooky::makeSafe {
Subroutine makeSafe: not called CC=1 SCAR=6.9
806 0 $noCache = 1;
807 }
808  
809 0 ▶sub FreezeThaw::FCooky::repeatedOK {
Subroutine repeatedOK: not called CC=1 SCAR=6.9
810 0 !$norepeated;
811 }
812  
813 0 ▶sub FreezeThaw::FCooky::noRepeated {
Subroutine noRepeated: not called CC=1 SCAR=6.9
814 0 $norepeated = 1;
815 }
816  
817 0 ▶sub FreezeThaw::TCooky::repeatedOK {
Subroutine repeatedOK: not called CC=1 SCAR=6.9
818 0 $uninitOK;
819 }
820  
821 0 ▶sub FreezeThaw::TCooky::noRepeated {
Subroutine noRepeated: not called CC=1 SCAR=6.9
822 0 undef $uninitOK;
823 }
824  
825 0 ▶sub FreezeThaw::TCooky::isSafe {
Subroutine isSafe: not called CC=1 SCAR=6.9
826 0 !$unsafe;
827 }
828  
829 0 ▶sub FreezeThaw::TCooky::makeSafe {
Subroutine makeSafe: not called CC=1 SCAR=6.9
830 0 undef $unsafe;
831 }
832  
833 19 ▶sub FreezeThaw::TCooky::ThawScalar {
Subroutine ThawScalar: called CC=1 SCAR=0.0
834 19 my $self = shift;
835 19 my ($res,$off) = &thawScalar($$self);
836 19 $$self = $off;
837 19 $res;
838 }
839  
840 33 ▶sub UNIVERSAL::Freeze {
Subroutine Freeze: called CC=1 SCAR=0.0
Pod undocumented
841 33 my ($obj, $cooky) = (shift, shift);
842 33 $cooky->FreezeScalar($obj,1,1);
843 }
844  
845 12 ▶sub UNIVERSAL::Thaw {
Subroutine Thaw: called CC=1 SCAR=0.0
Pod undocumented
846 12 my ($package, $cooky) = (shift, shift);
847 12 my $obj = $cooky->ThawScalar;
848 12 bless $obj, $package;
849 }
850  
851 12 ▶sub UNIVERSAL::FreezeInstance {
Subroutine FreezeInstance: called CC=1 SCAR=0.0
Pod undocumented
852 12 my($obj,$cooky) = @_;
853 12 return if !RexIsREGEXP # Special-case non-1st-class RExes
854 and ref $obj and (haveIsRex ? re::is_regexp($obj)
855 : (ref $obj eq 'Regexp' and not defined $$obj)); # Regexp
856 12 $obj->Freeze($cooky);
857 }
858  
859 7 ▶sub UNIVERSAL::Instantiate {
Subroutine Instantiate: called CC=1 SCAR=0.0
Pod undocumented
860 7 my($package,$pre,$cooky) = @_;
861 7 return if !RexIsREGEXP and $package eq 'Regexp';
862 7 my $obj = $package->Thaw($cooky);
863 # SvAMAGIC() is a property of a reference, not of a referent!
864 # Thus we cannot use $pre here if $obj was overloaded...
865 7 copyContents $_[1], $obj;
866 }
867  
868 7 ▶sub UNIVERSAL::Allocate {
Subroutine Allocate: called CC=1 SCAR=0.0
Pod undocumented
869 7 my($package,$cooky) = @_;
870 7 $cooky->ThawScalar;
871 }
872  
873 12 ▶sub UNIVERSAL::FreezeEmpty {
Subroutine FreezeEmpty: called CC=3 SCAR=13.1
Pod undocumented
874 12 my $obj = shift;
875 12 my $type = getref $obj;
876 12 my $e = $Empty{$type};
877 12 ▶ if (ref $e) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $e) { } 12 0 12
elsif ($e) { } 0 0 0
878 12 my $ref = &$e;
879 12 freezeScalar $ref;
880 12 $ref; # Put into cache.
881 } elsif ($e) {
882 0 freezeScalar($obj,1,1); # Atomic
883 0 undef;
884 } elsif (!RexIsREGEXP and defined $e and not defined $$obj) { # REx pre-5.11
885 freezeREx($obj);
886 undef;
887 } else {
888 0 die "Do not know how to FreezeEmpty $type";
889 }
890 }
891  
892 2 1;
↑ Summary