blib/lib/Storable.pm

filter: Statementstmt 96.8% 527 / 544 Branchbran 67.7% 84 / 124 Conditioncond 75.0% 15 / 20 MC/DCmcdc 54.5% 6 / 11 Subroutinesub 95.7% 135 / 141 Podpod 11.1% 2 / 18 totaltotal 89.6% 769 / 858 CC 67 SCAR 14.6
CC
67
Cov
91%
read_magic
18.4
_store
13.1
BEGIN
9.7
CRAP 4.3
↑ Summary Storable.xs »
1 #
2 # Copyright (c) 1995-2001, Raphael Manfredi
3 # Copyright (c) 2002-2014 by the Perl 5 Porters
4 # Copyright (c) 2015-2016 cPanel Inc
5 # Copyright (c) 2017 Reini Urban
6 #
7 # You may redistribute only under the same terms as Perl 5, as specified
8 # in the README file that comes with the distribution.
9 #
10  
11 package Storable;
12 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 47 ▶use XSLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 47 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 47 our @ISA = qw(Exporter);
18 47 our @EXPORT = qw(store retrieve);
19 47 our @EXPORT_OK = qw(
20 nstore store_fd nstore_fd fd_retrieve
21 freeze nfreeze thaw
22 dclone
23 retrieve_fd
24 lock_store lock_nstore lock_retrieve
25 file_magic read_magic
26 BLESS_OK TIE_OK FLAGS_COMPAT
27 stack_depth stack_depth_hash
28 );
29  
30 47 our ($canonical, $forgive_me);
31  
32 47 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
33 47 our $VERSION = '3.41';
34 }
35  
36 47 our $recursion_limit;
37 47 our $recursion_limit_hash;
38  
39 47 ▶$recursion_limit = 512
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Storable::recursion_limit 47 0 47
40 unless defined $recursion_limit;
41 47 ▶$recursion_limit_hash = 256
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Storable::recursion_limit_hash 47 0 47
42 unless defined $recursion_limit_hash;
43  
44 47 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 47 ▶use Fcntl qw(LOCK_SH LOCK_EX);
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 47 ▶BEGIN {
Subroutine BEGIN: called CC=7 SCAR=22.8
48 47 ▶ if (eval {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { local $SIG{"__DIE__"}; local(@INC) = @INC; pop @INC if $INC[-1] eq "."; require Log::Agent; 1 } }) 0 47 47
49 47 local $SIG{__DIE__};
50 47 local @INC = @INC;
51 47 ▶ pop @INC if $INC[-1] eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $INC[-1] eq "." 44 3 47
52 47 require Log::Agent;
53 0 1;
54 }) {
55 0 Log::Agent->import;
56 }
57 #
58 # Use of Log::Agent is optional. If it hasn't imported these subs then
59 # provide a fallback implementation.
60 #
61 47 ▶ unless ($Storable::{logcroak} && *{$Storable::{logcroak}}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Storable::{'logcroak'} and *{$main::Storable::{'logcroak'};}{'CODE'}) { } 0 47 47
Condition50%1/2
$main::Storable::{"logcroak"} and *{$main::Storable::{"logcroak"};}{"CODE"}
!ll
047
MC/DC0%0/1
$main::Storable::{"logcroak"} and *{$main::Storable::{"logcroak"};}{"CODE"}
$main::Storable::{"logcroak"}
Truth table50%1/2
A
A= $main::Storable::{"logcroak"}
Aresult
00
11
62 47 *logcroak = \&Carp::croak;
63 }
64 else {
65 # Log::Agent's logcroak always adds a newline to the error it is
66 # given. This breaks refs getting thrown. We can just discard what
67 # it throws (but keep whatever logging it does) and throw the original
68 # args.
69 47 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
70 0 my $logcroak = \&logcroak;
71 0 ▶ *logcroak = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 my @args = @_;
73 0 eval { &$logcroak };
74 0 Carp::croak(@args);
75 0 };
76 }
77 47 ▶ unless ($Storable::{logcarp} && *{$Storable::{logcarp}}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($main::Storable::{"logcarp"} and *{$main::Storable::{"logcarp"};}{"CODE"}) 47 0 47
Condition50%1/2
$main::Storable::{"logcarp"} and *{$main::Storable::{"logcarp"};}{"CODE"}
!ll
047
MC/DC0%0/1
$main::Storable::{"logcarp"} and *{$main::Storable::{"logcarp"};}{"CODE"}
$main::Storable::{"logcarp"}
Truth table50%1/2
A
A= $main::Storable::{"logcarp"}
Aresult
00
11
78 47 *logcarp = \&Carp::carp;
79 }
80 }
81  
82 0 ▶sub CLONE {
Subroutine CLONE: not called CC=1 SCAR=6.9
83 # clone context under threads
84 0 Storable::init_perinterp();
85 }
86  
87 sub BLESS_OK () { 2 }
88 sub TIE_OK () { 4 }
89 sub FLAGS_COMPAT () { BLESS_OK | TIE_OK }
90  
91 # By default restricted hashes are downgraded on earlier perls.
92  
93 47 our $flags = FLAGS_COMPAT;
94 47 our $downgrade_restricted = 1;
95 47 our $accept_future_minor = 1;
96  
97 47 ▶BEGIN { XSLoader::load('Storable') };
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99 #
100 # Determine whether locking is possible, but only when needed.
101 #
102  
103 0 ▶sub show_file_magic {
Subroutine show_file_magic: not called CC=1 SCAR=6.9
Pod undocumented
104 0 print <<EOM;
105 #
106 # To recognize the data files of the Perl module Storable,
107 # the following lines need to be added to the local magic(5) file,
108 # usually either /usr/share/misc/magic or /etc/magic.
109 #
110 0 string perl-store perl Storable(v0.6) data
111 >4 byte >0 (net-order %d)
112 >>4 byte &01 (network-ordered)
113 >>4 byte =3 (major 1)
114 >>4 byte =2 (major 1)
115  
116 0 string pst0 perl Storable(v0.7) data
117 >4 byte >0
118 >>4 byte &01 (network-ordered)
119 >>4 byte =5 (major 2)
120 >>4 byte =4 (major 2)
121 >>5 byte >0 (minor %d)
122 EOM
123 }
124  
125 28 ▶sub file_magic {
Subroutine file_magic: called CC=4 SCAR=14.0
Pod documented
126 28 my $file = shift;
127 28 ▶ open(my $fh, "<", $file) || die "Can't open '$file': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Can't open '${file}': $!" 27 1 28
128 27 binmode($fh);
129 27 ▶ defined(sysread($fh, my $buf, 32)) || die "Can't read from '$file': $!";
Branch: 1 branch
BranchTrueFalseTotal
defined sysread($fh, my $buf, 32) or die "Can't read from '${file}': $!" 27 0 27
130 27 close($fh);
131  
132 27 ▶ $file = "./$file" unless $file; # ensure TRUE value
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 27 27
133  
134 27 return read_magic($buf, $file);
135 }
136  
137 55 ▶sub read_magic {
Subroutine read_magic: called CC=18 SCAR=29.1
Pod documented
138 55 my($buf, $file) = @_;
139 55 my %info;
140  
141 55 my $buflen = length($buf);
142 55 my $magic;
143 55 ▶ if ($buf =~ s/^(pst0|perl-store)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ s/^(pst0|perl-store)//) { } 52 3 55
144 52 $magic = $1;
145 52 ▶ $info{file} = $file || 1;
Condition100%2/2
$file || 1
l!l
2626
MC/DC100%1/1
$file || 1
$file
Truth table100%2/2
A
A= $file
Aresult
11
00
146 }
147 else {
148 3 ▶ return undef if $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file 1 2 3
149 2 $magic = "";
150 }
151  
152 54 ▶ return undef unless length($buf);
Branch: 1 branch
BranchTrueFalseTotal
unless length $buf 0 54 54
153  
154 54 my $net_order;
155 54 ▶ if ($magic eq "perl-store" && ord(substr($buf, 0, 1)) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($magic eq 'perl-store' and ord substr($buf, 0, 1) > 1) { } 2 52 54
Condition100%3/3
$magic eq "perl-store" and ord substr($buf, 0, 1) > 1
!ll&&!rl&&r
4842
MC/DC100%2/2
$magic eq "perl-store" and ord substr($buf, 0, 1) > 1
$magic eq "perl-store" ord substr($buf, 0, 1) > 1
Truth table100%3/3
A and B
A= $magic eq "perl-store"B= ord substr($buf, 0, 1) > 1
ABresult
0X0
100
111
156 2 $info{version} = -1;
157 2 $net_order = 0;
158 }
159 else {
160 52 $buf =~ s/(.)//s;
161 52 my $major = (ord $1) >> 1;
162 52 ▶ return undef if $major > 4; # sanity (assuming we never go that high)
Branch: 1 branch
BranchTrueFalseTotal
if $major > 4 0 52 52
163 52 $info{major} = $major;
164 52 $net_order = (ord $1) & 0x01;
165 52 ▶ if ($major > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($major > 1) { } 44 8 52
166 44 ▶ return undef unless $buf =~ s/(.)//s;
Branch: 1 branch
BranchTrueFalseTotal
unless $buf =~ s/(.)//s 0 44 44
167 44 my $minor = ord $1;
168 44 $info{minor} = $minor;
169 44 $info{version} = "$major.$minor";
170 44 $info{version_nv} = sprintf "%d.%03d", $major, $minor;
171 }
172 else {
173 8 $info{version} = $major;
174 }
175 }
176 54 ▶ $info{version_nv} ||= $info{version};
Condition100%3/3
$info{"version_nv"} ||= $info{"version"}
l!l&&r!l&&!r
4464
MC/DC100%2/2
$info{"version_nv"} ||= $info{"version"}
$info{"version_nv"} $info{"version"}
Truth table100%3/3
A ||= B
A= $info{"version_nv"}B= $info{"version"}
ABresult
1X1
011
000
177 54 $info{netorder} = $net_order;
178  
179 54 ▶ unless ($net_order) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($net_order) 33 21 54
180 33 ▶ return undef unless $buf =~ s/(.)//s;
Branch: 1 branch
BranchTrueFalseTotal
unless $buf =~ s/(.)//s 0 33 33
181 33 my $len = ord $1;
182 33 ▶ return undef unless length($buf) >= $len;
Branch: 1 branch
BranchTrueFalseTotal
unless length $buf >= $len 0 33 33
183 33 ▶ return undef unless $len == 4 || $len == 8; # sanity
Branch: 1 branch
BranchTrueFalseTotal
unless $len == 4 or $len == 8 0 33 33
Condition66%2/3
$len == 4 or $len == 8
l!l&&r!l&&!r
2490
MC/DC0%0/2
$len == 4 or $len == 8
$len == 4 $len == 8
Truth table66%2/3
A or B
A= $len == 4B= $len == 8
ABresult
1X1
011
000
184 33 @info{qw(byteorder intsize longsize ptrsize)}
185 = unpack "a${len}CCC", $buf;
186 33 (substr $buf, 0, $len + 3) = '';
187 33 ▶ if ($info{version_nv} >= 2.002) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info{"version_nv"} >= "2.002") 25 8 33
188 25 ▶ return undef unless $buf =~ s/(.)//s;
Branch: 1 branch
BranchTrueFalseTotal
unless $buf =~ s/(.)//s 0 25 25
189 25 $info{nvsize} = ord $1;
190 }
191 }
192 54 $info{hdrsize} = $buflen - length($buf);
193  
194 54 return \%info;
195 }
196  
197 0 ▶sub BIN_VERSION_NV {
Subroutine BIN_VERSION_NV: not called CC=1 SCAR=6.9
Pod undocumented
198 0 sprintf "%d.%03d", BIN_MAJOR(), BIN_MINOR();
199 }
200  
201 2 ▶sub BIN_WRITE_VERSION_NV {
Subroutine BIN_WRITE_VERSION_NV: called CC=1 SCAR=0.0
Pod undocumented
202 2 sprintf "%d.%03d", BIN_MAJOR(), BIN_WRITE_MINOR();
203 }
204  
205 #
206 # store
207 #
208 # Store target object hierarchy, identified by a reference to its root.
209 # The stored object tree may later be retrieved to memory via retrieve.
210 # Returns undef if an I/O error occurred, in which case the file is
211 # removed.
212 #
213 55 ▶sub store {
Subroutine store: called CC=1 SCAR=0.0
Pod undocumented
214 55 return _store(\&pstore, @_, 0);
215 }
216  
217 #
218 # nstore
219 #
220 # Same as store, but in network order.
221 #
222 45 ▶sub nstore {
Subroutine nstore: called CC=1 SCAR=0.0
Pod undocumented
223 45 return _store(\&net_pstore, @_, 0);
224 }
225  
226 #
227 # lock_store
228 #
229 # Same as store, but flock the file first (advisory locking).
230 #
231 1 ▶sub lock_store {
Subroutine lock_store: called CC=1 SCAR=0.0
Pod undocumented
232 1 return _store(\&pstore, @_, 1);
233 }
234  
235 #
236 # lock_nstore
237 #
238 # Same as nstore, but flock the file first (advisory locking).
239 #
240 0 ▶sub lock_nstore {
Subroutine lock_nstore: not called CC=1 SCAR=6.9
Pod undocumented
241 0 return _store(\&net_pstore, @_, 1);
242 }
243  
244 # Internal store to file routine
245 101 ▶sub _store {
Subroutine _store: called CC=13 SCAR=25.7
246 101 my $xsptr = shift;
247 101 my $self = shift;
248 101 my ($file, $use_locking) = @_;
249 101 ▶ logcroak "not a reference" unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 101 101
250 101 ▶ logcroak "wrong argument number" unless @_ == 2; # No @foo in arglist
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 101 101
251 101 my $FILE;
252 101 ▶ if ($use_locking) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_locking) { } 1 100 101
253 1 ▶ open($FILE, ">>", $file) || logcroak "can't write into $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $FILE, ">>", $file or logcroak("can't write into ${file}: $!") 1 0 1
254 1 unless (CAN_FLOCK) {
255 logcarp
256 "Storable::lock_store: fcntl/flock emulation broken on $^O";
257 return undef;
258 }
259 1 ▶ flock($FILE, LOCK_EX) ||
Branch: 1 branch
BranchTrueFalseTotal
flock $FILE, 2 or logcroak("can't get exclusive lock on ${file}: $!") 1 0 1
260 logcroak "can't get exclusive lock on $file: $!";
261 1 truncate $FILE, 0;
262 # Unlocking will happen when FILE is closed
263 } else {
264 100 ▶ open($FILE, ">", $file) || logcroak "can't create $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $FILE, ">", $file or logcroak("can't create ${file}: $!") 100 0 100
265 }
266 101 binmode $FILE; # Archaic systems...
267 101 my $da = $@; # Don't mess if called from exception handler
268 101 my $ret;
269 # Call C routine nstore or pstore, depending on network order
270 101 ▶ eval { $ret = &$xsptr($FILE, $self) };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
271 # close will return true on success, so the or short-circuits, the ()
272 # expression is true, and for that case the block will only be entered
273 # if $@ is true (ie eval failed)
274 # if close fails, it returns false, $ret is altered, *that* is (also)
275 # false, so the () expression is false, !() is true, and the block is
276 # entered.
277 101 ▶ if (!(close($FILE) or undef $ret) || $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not close $FILE || undef $ret or $@) 3 98 101
Condition60%3/5
not close $FILE || undef $ret or $@
l!l&&r!l&&!r
0398
close $FILE || undef $ret
l!l
1010
MC/DC50%1/2
not close $FILE || undef $ret or $@
close $FILE $@
Truth table66%2/3
not(A) or B
A= close $FILEB= $@
ABresult
0X1
111
100
278 3 ▶ unlink($file) or warn "Can't unlink $file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
unlink $file or warn "Can't unlink ${file}: $!\n" 3 0 3
279 }
280 101 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 3 98 101
281 3 ▶ $@ =~ s/\.?\n$/,/ unless ref $@;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $@ 2 1 3
282 3 logcroak $@;
283 }
284 98 $@ = $da;
285 98 return $ret;
286 }
287  
288 #
289 # store_fd
290 #
291 # Same as store, but perform on an already opened file descriptor instead.
292 # Returns undef if an I/O error occurred.
293 #
294 1 ▶sub store_fd {
Subroutine store_fd: called CC=1 SCAR=0.0
Pod undocumented
295 1 return _store_fd(\&pstore, @_);
296 }
297  
298 #
299 # nstore_fd
300 #
301 # Same as store_fd, but in network order.
302 #
303 2 ▶sub nstore_fd {
Subroutine nstore_fd: called CC=1 SCAR=0.0
Pod undocumented
304 2 my ($self, $file) = @_;
305 2 return _store_fd(\&net_pstore, @_);
306 }
307  
308 # Internal store routine on opened file descriptor
309 3 ▶sub _store_fd {
Subroutine _store_fd: called CC=5 SCAR=16.2
310 3 my $xsptr = shift;
311 3 my $self = shift;
312 3 my ($file) = @_;
313 3 ▶ logcroak "not a reference" unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 3 3
314 3 ▶ logcroak "too many arguments" unless @_ == 1; # No @foo in arglist
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 3 3
315 3 my $fd = fileno($file);
316 3 ▶ logcroak "not a valid file descriptor" unless defined $fd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fd 0 3 3
317 3 $file = do {
318 47 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
319 3 \*{ $file };
320 };
321 3 my $da = $@; # Don't mess if called from exception handler
322 3 my $ret;
323 # Call C routine nstore or pstore, depending on network order
324 3 eval { $ret = &$xsptr($file, $self) };
325 3 ▶ logcroak $@ if $@ =~ s/\.?\n$/,/;
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ s/\.?\n$/,/ 0 3 3
326 3 local $\;
327 3 print $file ''; # Autoflush the file if wanted
328 3 $@ = $da;
329 3 return $ret;
330 }
331  
332 #
333 # freeze
334 #
335 # Store object and its hierarchy in memory and return a scalar
336 # containing the result.
337 #
338 235 ▶sub freeze {
Subroutine freeze: called CC=1 SCAR=0.0
Pod undocumented
339 235 _freeze(\&mstore, @_);
340 }
341  
342 #
343 # nfreeze
344 #
345 # Same as freeze but in network order.
346 #
347 45 ▶sub nfreeze {
Subroutine nfreeze: called CC=1 SCAR=0.0
Pod undocumented
348 45 _freeze(\&net_mstore, @_);
349 }
350  
351 # Internal freeze routine
352 280 ▶sub _freeze {
Subroutine _freeze: called CC=6 SCAR=17.9
353 280 my $xsptr = shift;
354 280 my $self = shift;
355 280 ▶ logcroak "not a reference" unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 280 280
356 280 ▶ logcroak "too many arguments" unless @_ == 0; # No @foo in arglist
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 280 280
357 280 my $da = $@; # Don't mess if called from exception handler
358 280 my $ret;
359 # Call C routine mstore or net_mstore, depending on network order
360 280 ▶ eval { $ret = &$xsptr($self) };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
361 280 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 7 273 280
362 7 ▶ $@ =~ s/\.?\n$/,/ unless ref $@;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $@ 6 1 7
363 7 logcroak $@;
364 }
365 273 $@ = $da;
366 273 ▶ return $ret ? $ret : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ret ? : 273 0 273
367 }
368  
369 #
370 # retrieve
371 #
372 # Retrieve object hierarchy from disk, returning a reference to the root
373 # object of that tree.
374 #
375 # retrieve(file, flags)
376 # flags include by default BLESS_OK=2 | TIE_OK=4
377 # with flags=0 or the global $Storable::flags set to 0, no resulting object
378 # will be blessed nor tied.
379 #
380 188 ▶sub retrieve {
Subroutine retrieve: called CC=1 SCAR=0.0
Pod undocumented
381 188 _retrieve(shift, 0, @_);
382 }
383  
384 #
385 # lock_retrieve
386 #
387 # Same as retrieve, but with advisory locking.
388 #
389 1 ▶sub lock_retrieve {
Subroutine lock_retrieve: called CC=1 SCAR=0.0
Pod undocumented
390 1 _retrieve(shift, 1, @_);
391 }
392  
393 # Internal retrieve routine
394 189 ▶sub _retrieve {
Subroutine _retrieve: called CC=7 SCAR=19.5
395 189 my ($file, $use_locking, $flags) = @_;
396 189 ▶ $flags = $Storable::flags unless defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 189 0 189
397 189 my $FILE;
398 189 ▶ open($FILE, "<", $file) || logcroak "can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $FILE, "<", $file or logcroak("can't open ${file}: $!") 189 0 189
399 189 binmode $FILE; # Archaic systems...
400 189 my $self;
401 189 my $da = $@; # Could be from exception handler
402 189 ▶ if ($use_locking) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_locking) 1 188 189
403 1 unless (CAN_FLOCK) {
404 logcarp
405 "Storable::lock_store: fcntl/flock emulation broken on $^O";
406 return undef;
407 }
408 1 ▶ flock($FILE, LOCK_SH) || logcroak "can't get shared lock on $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $FILE, 1 or logcroak("can't get shared lock on ${file}: $!") 1 0 1
409 # Unlocking will happen when FILE is closed
410 }
411 189 ▶ eval { $self = pretrieve($FILE, $flags) }; # Call C routine
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
412 189 close($FILE);
413 189 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 48 141 189
414 48 ▶ $@ =~ s/\.?\n$/,/ unless ref $@;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $@ 47 1 48
415 48 logcroak $@;
416 }
417 141 $@ = $da;
418 141 return $self;
419 }
420  
421 #
422 # fd_retrieve
423 #
424 # Same as retrieve, but perform from an already opened file descriptor instead.
425 #
426 11 ▶sub fd_retrieve {
Subroutine fd_retrieve: called CC=5 SCAR=16.1
Pod undocumented
427 11 my ($file, $flags) = @_;
428 11 ▶ $flags = $Storable::flags unless defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 11 0 11
429 11 my $fd = fileno($file);
430 11 ▶ logcroak "not a valid file descriptor" unless defined $fd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fd 0 11 11
431 11 my $self;
432 11 my $da = $@; # Could be from exception handler
433 11 eval { $self = pretrieve($file, $flags) }; # Call C routine
434 11 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 7 4 11
435 7 ▶ $@ =~ s/\.?\n$/,/ unless ref $@;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $@ 6 1 7
436 7 logcroak $@;
437 }
438 4 $@ = $da;
439 4 return $self;
440 }
441  
442 0 ▶sub retrieve_fd { &fd_retrieve } # Backward compatibility
Subroutine retrieve_fd: not called CC=1 SCAR=6.9
Pod undocumented
443  
444 #
445 # thaw
446 #
447 # Recreate objects in memory from an existing frozen image created
448 # by freeze. If the frozen image passed is undef, return undef.
449 #
450 # thaw(frozen_obj, flags)
451 # flags include by default BLESS_OK=2 | TIE_OK=4
452 # with flags=0 or the global $Storable::flags set to 0, no resulting object
453 # will be blessed nor tied.
454 #
455 375 ▶sub thaw {
Subroutine thaw: called CC=5 SCAR=16.1
Pod undocumented
456 375 my ($frozen, $flags) = @_;
457 375 ▶ $flags = $Storable::flags unless defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 370 5 375
458 375 ▶ return undef unless defined $frozen;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $frozen 0 375 375
459 375 my $self;
460 375 my $da = $@; # Could be from exception handler
461 375 ▶ eval { $self = mretrieve($frozen, $flags) }; # Call C routine
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
462 375 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 53 322 375
463 53 ▶ $@ =~ s/\.?\n$/,/ unless ref $@;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $@ 52 1 53
464 53 logcroak $@;
465 }
466 322 $@ = $da;
467 322 return $self;
468 }
469  
470 #
471 # _make_re($re, $flags)
472 #
473 # Internal function used to thaw a regular expression.
474 #
475  
476 47 my $re_flags;
477 47 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=18.9
478 47 ▶ if ($] < 5.010) {
Branch: 3 branches
BranchTrueFalseTotal
if ($] < 5.01) { } 0 47 47
elsif ($] < 5.014) { } 0 47 47
elsif ($] < 5.022) { } 0 47 47
479 0 $re_flags = qr/\A[imsx]*\z/;
480 }
481 elsif ($] < 5.014) {
482 0 $re_flags = qr/\A[msixp]*\z/;
483 }
484 elsif ($] < 5.022) {
485 0 $re_flags = qr/\A[msixpdual]*\z/;
486 }
487 else {
488 47 $re_flags = qr/\A[msixpdualn]*\z/;
489 }
490 }
491  
492 41 ▶sub _make_re {
Subroutine _make_re: called CC=3 SCAR=11.0
493 41 my ($re, $flags) = @_;
494  
495 41 ▶ $flags =~ $re_flags
Branch: 1 branch
BranchTrueFalseTotal
$flags =~ /$re_flags/ or die "regexp flags invalid" 41 0 41
496 or die "regexp flags invalid";
497  
498 41 my $qr = eval "qr/\$re/$flags";
499 41 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 40 41
500  
501 40 $qr;
502 }
503  
504 47 ▶if ($] < 5.012) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.012") 0 47 47
505 eval <<'EOS'
506 sub _regexp_pattern {
507 my $re = "" . shift;
508 $re =~ /\A\(\?([xism]*)(?:-[xism]*)?:(.*)\)\z/s
509 or die "Cannot parse regexp /$re/";
510 return ($2, $1);
511 }
512 1
513 EOS
514 0 ▶ or die "Cannot define _regexp_pattern: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval "sub _regexp_pattern {\n my \$re = \"\" . shift;\n \$re =~ /\\A\\(\\?([xism]*)(?:-[xism]*)?:(.*)\\)\\z/s\n or die \"Cannot parse regexp /\$re/\";\n return (\$2, \$1);\n}\n1\n" or die "Cannot define _regexp_pattern: $@" 0 0 0
515 }
516  
517 47 1;
518 __END__
↑ Summary Storable.xs »