Filename | /usr/local/perls/perl-5.26.1/lib/5.26.1/darwin-2level/Storable.pm |
Statements | Executed 41 statements in 657ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 650ms | 650ms | pretrieve (xsub) | Storable::
1 | 1 | 1 | 103µs | 103µs | CORE:open (opcode) | Storable::
1 | 1 | 1 | 83µs | 650ms | _retrieve | Storable::
1 | 1 | 1 | 71µs | 71µs | BEGIN@27 | Storable::
1 | 1 | 1 | 29µs | 117µs | BEGIN@23 | Storable::
1 | 1 | 1 | 20µs | 20µs | CORE:close (opcode) | Storable::
1 | 1 | 1 | 15µs | 328µs | BEGIN@59 | Storable::
1 | 1 | 1 | 12µs | 650ms | retrieve | Storable::
1 | 1 | 1 | 3µs | 3µs | CORE:binmode (opcode) | Storable::
1 | 1 | 1 | 2µs | 2µs | CORE:subst (opcode) | Storable::
0 | 0 | 0 | 0s | 0s | BIN_VERSION_NV | Storable::
0 | 0 | 0 | 0s | 0s | BIN_WRITE_VERSION_NV | Storable::
0 | 0 | 0 | 0s | 0s | CAN_FLOCK | Storable::
0 | 0 | 0 | 0s | 0s | CLONE | Storable::
0 | 0 | 0 | 0s | 0s | __ANON__[:45] | Storable::
0 | 0 | 0 | 0s | 0s | __ANON__[:51] | Storable::
0 | 0 | 0 | 0s | 0s | _freeze | Storable::
0 | 0 | 0 | 0s | 0s | _store | Storable::
0 | 0 | 0 | 0s | 0s | _store_fd | Storable::
0 | 0 | 0 | 0s | 0s | fd_retrieve | Storable::
0 | 0 | 0 | 0s | 0s | file_magic | Storable::
0 | 0 | 0 | 0s | 0s | freeze | Storable::
0 | 0 | 0 | 0s | 0s | lock_nstore | Storable::
0 | 0 | 0 | 0s | 0s | lock_retrieve | Storable::
0 | 0 | 0 | 0s | 0s | lock_store | Storable::
0 | 0 | 0 | 0s | 0s | nfreeze | Storable::
0 | 0 | 0 | 0s | 0s | nstore | Storable::
0 | 0 | 0 | 0s | 0s | nstore_fd | Storable::
0 | 0 | 0 | 0s | 0s | read_magic | Storable::
0 | 0 | 0 | 0s | 0s | retrieve_fd | Storable::
0 | 0 | 0 | 0s | 0s | show_file_magic | Storable::
0 | 0 | 0 | 0s | 0s | store | Storable::
0 | 0 | 0 | 0s | 0s | store_fd | Storable::
0 | 0 | 0 | 0s | 0s | thaw | Storable::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # | ||||
2 | # Copyright (c) 1995-2001, Raphael Manfredi | ||||
3 | # Copyright (c) 2002-2014 by the Perl 5 Porters | ||||
4 | # | ||||
5 | # You may redistribute only under the same terms as Perl 5, as specified | ||||
6 | # in the README file that comes with the distribution. | ||||
7 | # | ||||
8 | |||||
9 | 1 | 1µs | require XSLoader; | ||
10 | 1 | 1µs | require Exporter; | ||
11 | 1 | 13µs | package Storable; @ISA = qw(Exporter); | ||
12 | |||||
13 | 1 | 1µs | @EXPORT = qw(store retrieve); | ||
14 | 1 | 1µs | @EXPORT_OK = qw( | ||
15 | nstore store_fd nstore_fd fd_retrieve | ||||
16 | freeze nfreeze thaw | ||||
17 | dclone | ||||
18 | retrieve_fd | ||||
19 | lock_store lock_nstore lock_retrieve | ||||
20 | file_magic read_magic | ||||
21 | ); | ||||
22 | |||||
23 | 2 | 292µs | 2 | 205µs | # spent 117µs (29+88) within Storable::BEGIN@23 which was called:
# once (29µs+88µs) by CPAN::has_inst at line 23 # spent 117µs making 1 call to Storable::BEGIN@23
# spent 88µs making 1 call to vars::import |
24 | |||||
25 | 1 | 0s | $VERSION = '2.62'; | ||
26 | |||||
27 | # spent 71µs within Storable::BEGIN@27 which was called:
# once (71µs+0s) by CPAN::has_inst at line 53 | ||||
28 | 1 | 0s | if (eval { | ||
29 | 1 | 5µs | local $SIG{__DIE__}; | ||
30 | 1 | 5µs | local @INC = @INC; | ||
31 | 1 | 1µs | pop @INC if $INC[-1] eq '.'; | ||
32 | 1 | 43µs | require Log::Agent; | ||
33 | 1; | ||||
34 | }) { | ||||
35 | Log::Agent->import; | ||||
36 | } | ||||
37 | # | ||||
38 | # Use of Log::Agent is optional. If it hasn't imported these subs then | ||||
39 | # provide a fallback implementation. | ||||
40 | # | ||||
41 | 1 | 3µs | unless ($Storable::{logcroak} && *{$Storable::{logcroak}}{CODE}) { | ||
42 | 1 | 1µs | require Carp; | ||
43 | *logcroak = sub { | ||||
44 | Carp::croak(@_); | ||||
45 | 1 | 3µs | }; | ||
46 | } | ||||
47 | 1 | 7µs | unless ($Storable::{logcarp} && *{$Storable::{logcarp}}{CODE}) { | ||
48 | 1 | 0s | require Carp; | ||
49 | *logcarp = sub { | ||||
50 | Carp::carp(@_); | ||||
51 | 1 | 1µs | }; | ||
52 | } | ||||
53 | 1 | 85µs | 1 | 71µs | } # spent 71µs making 1 call to Storable::BEGIN@27 |
54 | |||||
55 | # | ||||
56 | # They might miss :flock in Fcntl | ||||
57 | # | ||||
58 | |||||
59 | # spent 328µs (15+313) within Storable::BEGIN@59 which was called:
# once (15µs+313µs) by CPAN::has_inst at line 68 | ||||
60 | 3 | 15µs | 1 | 313µs | if (eval { require Fcntl; 1 } && exists $Fcntl::EXPORT_TAGS{'flock'}) { # spent 313µs making 1 call to Exporter::import |
61 | Fcntl->import(':flock'); | ||||
62 | } else { | ||||
63 | eval q{ | ||||
64 | sub LOCK_SH () {1} | ||||
65 | sub LOCK_EX () {2} | ||||
66 | }; | ||||
67 | } | ||||
68 | 1 | 4.59ms | 1 | 328µs | } # spent 328µs making 1 call to Storable::BEGIN@59 |
69 | |||||
70 | sub CLONE { | ||||
71 | # clone context under threads | ||||
72 | Storable::init_perinterp(); | ||||
73 | } | ||||
74 | |||||
75 | # By default restricted hashes are downgraded on earlier perls. | ||||
76 | |||||
77 | 1 | 0s | $Storable::downgrade_restricted = 1; | ||
78 | 1 | 0s | $Storable::accept_future_minor = 1; | ||
79 | |||||
80 | 1 | 1.65ms | 1 | 1.64ms | XSLoader::load('Storable', $Storable::VERSION); # spent 1.64ms making 1 call to XSLoader::load |
81 | |||||
82 | # | ||||
83 | # Determine whether locking is possible, but only when needed. | ||||
84 | # | ||||
85 | |||||
86 | 1 | 0s | sub CAN_FLOCK; my $CAN_FLOCK; sub CAN_FLOCK { | ||
87 | return $CAN_FLOCK if defined $CAN_FLOCK; | ||||
88 | require Config; import Config; | ||||
89 | return $CAN_FLOCK = | ||||
90 | $Config{'d_flock'} || | ||||
91 | $Config{'d_fcntl_can_lock'} || | ||||
92 | $Config{'d_lockf'}; | ||||
93 | } | ||||
94 | |||||
95 | sub show_file_magic { | ||||
96 | print <<EOM; | ||||
97 | # | ||||
98 | # To recognize the data files of the Perl module Storable, | ||||
99 | # the following lines need to be added to the local magic(5) file, | ||||
100 | # usually either /usr/share/misc/magic or /etc/magic. | ||||
101 | # | ||||
102 | 0 string perl-store perl Storable(v0.6) data | ||||
103 | >4 byte >0 (net-order %d) | ||||
104 | >>4 byte &01 (network-ordered) | ||||
105 | >>4 byte =3 (major 1) | ||||
106 | >>4 byte =2 (major 1) | ||||
107 | |||||
108 | 0 string pst0 perl Storable(v0.7) data | ||||
109 | >4 byte >0 | ||||
110 | >>4 byte &01 (network-ordered) | ||||
111 | >>4 byte =5 (major 2) | ||||
112 | >>4 byte =4 (major 2) | ||||
113 | >>5 byte >0 (minor %d) | ||||
114 | EOM | ||||
115 | } | ||||
116 | |||||
117 | sub file_magic { | ||||
118 | require IO::File; | ||||
119 | |||||
120 | my $file = shift; | ||||
121 | my $fh = IO::File->new; | ||||
122 | open($fh, "<", $file) || die "Can't open '$file': $!"; | ||||
123 | binmode($fh); | ||||
124 | defined(sysread($fh, my $buf, 32)) || die "Can't read from '$file': $!"; | ||||
125 | close($fh); | ||||
126 | |||||
127 | $file = "./$file" unless $file; # ensure TRUE value | ||||
128 | |||||
129 | return read_magic($buf, $file); | ||||
130 | } | ||||
131 | |||||
132 | sub read_magic { | ||||
133 | my($buf, $file) = @_; | ||||
134 | my %info; | ||||
135 | |||||
136 | my $buflen = length($buf); | ||||
137 | my $magic; | ||||
138 | if ($buf =~ s/^(pst0|perl-store)//) { | ||||
139 | $magic = $1; | ||||
140 | $info{file} = $file || 1; | ||||
141 | } | ||||
142 | else { | ||||
143 | return undef if $file; | ||||
144 | $magic = ""; | ||||
145 | } | ||||
146 | |||||
147 | return undef unless length($buf); | ||||
148 | |||||
149 | my $net_order; | ||||
150 | if ($magic eq "perl-store" && ord(substr($buf, 0, 1)) > 1) { | ||||
151 | $info{version} = -1; | ||||
152 | $net_order = 0; | ||||
153 | } | ||||
154 | else { | ||||
155 | $buf =~ s/(.)//s; | ||||
156 | my $major = (ord $1) >> 1; | ||||
157 | return undef if $major > 4; # sanity (assuming we never go that high) | ||||
158 | $info{major} = $major; | ||||
159 | $net_order = (ord $1) & 0x01; | ||||
160 | if ($major > 1) { | ||||
161 | return undef unless $buf =~ s/(.)//s; | ||||
162 | my $minor = ord $1; | ||||
163 | $info{minor} = $minor; | ||||
164 | $info{version} = "$major.$minor"; | ||||
165 | $info{version_nv} = sprintf "%d.%03d", $major, $minor; | ||||
166 | } | ||||
167 | else { | ||||
168 | $info{version} = $major; | ||||
169 | } | ||||
170 | } | ||||
171 | $info{version_nv} ||= $info{version}; | ||||
172 | $info{netorder} = $net_order; | ||||
173 | |||||
174 | unless ($net_order) { | ||||
175 | return undef unless $buf =~ s/(.)//s; | ||||
176 | my $len = ord $1; | ||||
177 | return undef unless length($buf) >= $len; | ||||
178 | return undef unless $len == 4 || $len == 8; # sanity | ||||
179 | @info{qw(byteorder intsize longsize ptrsize)} | ||||
180 | = unpack "a${len}CCC", $buf; | ||||
181 | (substr $buf, 0, $len + 3) = ''; | ||||
182 | if ($info{version_nv} >= 2.002) { | ||||
183 | return undef unless $buf =~ s/(.)//s; | ||||
184 | $info{nvsize} = ord $1; | ||||
185 | } | ||||
186 | } | ||||
187 | $info{hdrsize} = $buflen - length($buf); | ||||
188 | |||||
189 | return \%info; | ||||
190 | } | ||||
191 | |||||
192 | sub BIN_VERSION_NV { | ||||
193 | sprintf "%d.%03d", BIN_MAJOR(), BIN_MINOR(); | ||||
194 | } | ||||
195 | |||||
196 | sub BIN_WRITE_VERSION_NV { | ||||
197 | sprintf "%d.%03d", BIN_MAJOR(), BIN_WRITE_MINOR(); | ||||
198 | } | ||||
199 | |||||
200 | # | ||||
201 | # store | ||||
202 | # | ||||
203 | # Store target object hierarchy, identified by a reference to its root. | ||||
204 | # The stored object tree may later be retrieved to memory via retrieve. | ||||
205 | # Returns undef if an I/O error occurred, in which case the file is | ||||
206 | # removed. | ||||
207 | # | ||||
208 | sub store { | ||||
209 | return _store(\&pstore, @_, 0); | ||||
210 | } | ||||
211 | |||||
212 | # | ||||
213 | # nstore | ||||
214 | # | ||||
215 | # Same as store, but in network order. | ||||
216 | # | ||||
217 | sub nstore { | ||||
218 | return _store(\&net_pstore, @_, 0); | ||||
219 | } | ||||
220 | |||||
221 | # | ||||
222 | # lock_store | ||||
223 | # | ||||
224 | # Same as store, but flock the file first (advisory locking). | ||||
225 | # | ||||
226 | sub lock_store { | ||||
227 | return _store(\&pstore, @_, 1); | ||||
228 | } | ||||
229 | |||||
230 | # | ||||
231 | # lock_nstore | ||||
232 | # | ||||
233 | # Same as nstore, but flock the file first (advisory locking). | ||||
234 | # | ||||
235 | sub lock_nstore { | ||||
236 | return _store(\&net_pstore, @_, 1); | ||||
237 | } | ||||
238 | |||||
239 | # Internal store to file routine | ||||
240 | sub _store { | ||||
241 | my $xsptr = shift; | ||||
242 | my $self = shift; | ||||
243 | my ($file, $use_locking) = @_; | ||||
244 | logcroak "not a reference" unless ref($self); | ||||
245 | logcroak "wrong argument number" unless @_ == 2; # No @foo in arglist | ||||
246 | local *FILE; | ||||
247 | if ($use_locking) { | ||||
248 | open(FILE, '>>', $file) || logcroak "can't write into $file: $!"; | ||||
249 | unless (&CAN_FLOCK) { | ||||
250 | logcarp | ||||
251 | "Storable::lock_store: fcntl/flock emulation broken on $^O"; | ||||
252 | return undef; | ||||
253 | } | ||||
254 | flock(FILE, LOCK_EX) || | ||||
255 | logcroak "can't get exclusive lock on $file: $!"; | ||||
256 | truncate FILE, 0; | ||||
257 | # Unlocking will happen when FILE is closed | ||||
258 | } else { | ||||
259 | open(FILE, '>', $file) || logcroak "can't create $file: $!"; | ||||
260 | } | ||||
261 | binmode FILE; # Archaic systems... | ||||
262 | my $da = $@; # Don't mess if called from exception handler | ||||
263 | my $ret; | ||||
264 | # Call C routine nstore or pstore, depending on network order | ||||
265 | eval { $ret = &$xsptr(*FILE, $self) }; | ||||
266 | # close will return true on success, so the or short-circuits, the () | ||||
267 | # expression is true, and for that case the block will only be entered | ||||
268 | # if $@ is true (ie eval failed) | ||||
269 | # if close fails, it returns false, $ret is altered, *that* is (also) | ||||
270 | # false, so the () expression is false, !() is true, and the block is | ||||
271 | # entered. | ||||
272 | if (!(close(FILE) or undef $ret) || $@) { | ||||
273 | unlink($file) or warn "Can't unlink $file: $!\n"; | ||||
274 | } | ||||
275 | logcroak $@ if $@ =~ s/\.?\n$/,/; | ||||
276 | $@ = $da; | ||||
277 | return $ret; | ||||
278 | } | ||||
279 | |||||
280 | # | ||||
281 | # store_fd | ||||
282 | # | ||||
283 | # Same as store, but perform on an already opened file descriptor instead. | ||||
284 | # Returns undef if an I/O error occurred. | ||||
285 | # | ||||
286 | sub store_fd { | ||||
287 | return _store_fd(\&pstore, @_); | ||||
288 | } | ||||
289 | |||||
290 | # | ||||
291 | # nstore_fd | ||||
292 | # | ||||
293 | # Same as store_fd, but in network order. | ||||
294 | # | ||||
295 | sub nstore_fd { | ||||
296 | my ($self, $file) = @_; | ||||
297 | return _store_fd(\&net_pstore, @_); | ||||
298 | } | ||||
299 | |||||
300 | # Internal store routine on opened file descriptor | ||||
301 | sub _store_fd { | ||||
302 | my $xsptr = shift; | ||||
303 | my $self = shift; | ||||
304 | my ($file) = @_; | ||||
305 | logcroak "not a reference" unless ref($self); | ||||
306 | logcroak "too many arguments" unless @_ == 1; # No @foo in arglist | ||||
307 | my $fd = fileno($file); | ||||
308 | logcroak "not a valid file descriptor" unless defined $fd; | ||||
309 | my $da = $@; # Don't mess if called from exception handler | ||||
310 | my $ret; | ||||
311 | # Call C routine nstore or pstore, depending on network order | ||||
312 | eval { $ret = &$xsptr($file, $self) }; | ||||
313 | logcroak $@ if $@ =~ s/\.?\n$/,/; | ||||
314 | local $\; print $file ''; # Autoflush the file if wanted | ||||
315 | $@ = $da; | ||||
316 | return $ret; | ||||
317 | } | ||||
318 | |||||
319 | # | ||||
320 | # freeze | ||||
321 | # | ||||
322 | # Store object and its hierarchy in memory and return a scalar | ||||
323 | # containing the result. | ||||
324 | # | ||||
325 | sub freeze { | ||||
326 | _freeze(\&mstore, @_); | ||||
327 | } | ||||
328 | |||||
329 | # | ||||
330 | # nfreeze | ||||
331 | # | ||||
332 | # Same as freeze but in network order. | ||||
333 | # | ||||
334 | sub nfreeze { | ||||
335 | _freeze(\&net_mstore, @_); | ||||
336 | } | ||||
337 | |||||
338 | # Internal freeze routine | ||||
339 | sub _freeze { | ||||
340 | my $xsptr = shift; | ||||
341 | my $self = shift; | ||||
342 | logcroak "not a reference" unless ref($self); | ||||
343 | logcroak "too many arguments" unless @_ == 0; # No @foo in arglist | ||||
344 | my $da = $@; # Don't mess if called from exception handler | ||||
345 | my $ret; | ||||
346 | # Call C routine mstore or net_mstore, depending on network order | ||||
347 | eval { $ret = &$xsptr($self) }; | ||||
348 | logcroak $@ if $@ =~ s/\.?\n$/,/; | ||||
349 | $@ = $da; | ||||
350 | return $ret ? $ret : undef; | ||||
351 | } | ||||
352 | |||||
353 | # | ||||
354 | # retrieve | ||||
355 | # | ||||
356 | # Retrieve object hierarchy from disk, returning a reference to the root | ||||
357 | # object of that tree. | ||||
358 | # | ||||
359 | # spent 650ms (12µs+650) within Storable::retrieve which was called:
# once (12µs+650ms) by CPAN::Index::read_metadata_cache at line 575 of CPAN/Index.pm | ||||
360 | 1 | 7µs | 1 | 650ms | _retrieve($_[0], 0); # spent 650ms making 1 call to Storable::_retrieve |
361 | } | ||||
362 | |||||
363 | # | ||||
364 | # lock_retrieve | ||||
365 | # | ||||
366 | # Same as retrieve, but with advisory locking. | ||||
367 | # | ||||
368 | sub lock_retrieve { | ||||
369 | _retrieve($_[0], 1); | ||||
370 | } | ||||
371 | |||||
372 | # Internal retrieve routine | ||||
373 | # spent 650ms (83µs+650) within Storable::_retrieve which was called:
# once (83µs+650ms) by Storable::retrieve at line 360 | ||||
374 | 1 | 1µs | my ($file, $use_locking) = @_; | ||
375 | 1 | 2µs | local *FILE; | ||
376 | 1 | 118µs | 1 | 103µs | open(FILE, '<', $file) || logcroak "can't open $file: $!"; # spent 103µs making 1 call to Storable::CORE:open |
377 | 1 | 11µs | 1 | 3µs | binmode FILE; # Archaic systems... # spent 3µs making 1 call to Storable::CORE:binmode |
378 | 1 | 0s | my $self; | ||
379 | 1 | 1µs | my $da = $@; # Could be from exception handler | ||
380 | 1 | 0s | if ($use_locking) { | ||
381 | unless (&CAN_FLOCK) { | ||||
382 | logcarp | ||||
383 | "Storable::lock_store: fcntl/flock emulation broken on $^O"; | ||||
384 | return undef; | ||||
385 | } | ||||
386 | flock(FILE, LOCK_SH) || logcroak "can't get shared lock on $file: $!"; | ||||
387 | # Unlocking will happen when FILE is closed | ||||
388 | } | ||||
389 | 2 | 650ms | 1 | 650ms | eval { $self = pretrieve(*FILE) }; # Call C routine # spent 650ms making 1 call to Storable::pretrieve |
390 | 1 | 33µs | 1 | 20µs | close(FILE); # spent 20µs making 1 call to Storable::CORE:close |
391 | 1 | 8µs | 1 | 2µs | logcroak $@ if $@ =~ s/\.?\n$/,/; # spent 2µs making 1 call to Storable::CORE:subst |
392 | 1 | 1µs | $@ = $da; | ||
393 | 1 | 15µs | return $self; | ||
394 | } | ||||
395 | |||||
396 | # | ||||
397 | # fd_retrieve | ||||
398 | # | ||||
399 | # Same as retrieve, but perform from an already opened file descriptor instead. | ||||
400 | # | ||||
401 | sub fd_retrieve { | ||||
402 | my ($file) = @_; | ||||
403 | my $fd = fileno($file); | ||||
404 | logcroak "not a valid file descriptor" unless defined $fd; | ||||
405 | my $self; | ||||
406 | my $da = $@; # Could be from exception handler | ||||
407 | eval { $self = pretrieve($file) }; # Call C routine | ||||
408 | logcroak $@ if $@ =~ s/\.?\n$/,/; | ||||
409 | $@ = $da; | ||||
410 | return $self; | ||||
411 | } | ||||
412 | |||||
413 | sub retrieve_fd { &fd_retrieve } # Backward compatibility | ||||
414 | |||||
415 | # | ||||
416 | # thaw | ||||
417 | # | ||||
418 | # Recreate objects in memory from an existing frozen image created | ||||
419 | # by freeze. If the frozen image passed is undef, return undef. | ||||
420 | # | ||||
421 | sub thaw { | ||||
422 | my ($frozen) = @_; | ||||
423 | return undef unless defined $frozen; | ||||
424 | my $self; | ||||
425 | my $da = $@; # Could be from exception handler | ||||
426 | eval { $self = mretrieve($frozen) }; # Call C routine | ||||
427 | logcroak $@ if $@ =~ s/\.?\n$/,/; | ||||
428 | $@ = $da; | ||||
429 | return $self; | ||||
430 | } | ||||
431 | |||||
432 | 1 | 16µs | 1; | ||
433 | __END__ | ||||
# spent 3µs within Storable::CORE:binmode which was called:
# once (3µs+0s) by Storable::_retrieve at line 377 | |||||
# spent 20µs within Storable::CORE:close which was called:
# once (20µs+0s) by Storable::_retrieve at line 390 | |||||
# spent 103µs within Storable::CORE:open which was called:
# once (103µs+0s) by Storable::_retrieve at line 376 | |||||
# spent 2µs within Storable::CORE:subst which was called:
# once (2µs+0s) by Storable::_retrieve at line 391 | |||||
# spent 650ms within Storable::pretrieve which was called:
# once (650ms+0s) by Storable::_retrieve at line 389 |