X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/51f77169798efa27e731b2302c26b7e90d678185..b846e6a637ab20092fb1d9bc4bb317f92efaf0f0:/dist/Storable/Storable.pm?ds=sidebyside diff --git a/dist/Storable/Storable.pm b/dist/Storable/Storable.pm index b6bfa88..c2004f0 100644 --- a/dist/Storable/Storable.pm +++ b/dist/Storable/Storable.pm @@ -5,9 +5,9 @@ # in the README file that comes with the distribution. # -require DynaLoader; +require XSLoader; require Exporter; -package Storable; @ISA = qw(Exporter DynaLoader); +package Storable; @ISA = qw(Exporter); @EXPORT = qw(store retrieve); @EXPORT_OK = qw( @@ -19,24 +19,32 @@ package Storable; @ISA = qw(Exporter DynaLoader); file_magic read_magic ); -use AutoLoader; -use FileHandle; use vars qw($canonical $forgive_me $VERSION); -$VERSION = '2.24'; -*AUTOLOAD = \&AutoLoader::AUTOLOAD; # Grrr... +$VERSION = '2.38'; -# -# Use of Log::Agent is optional -# - -{ - local $SIG{__DIE__}; - eval "use Log::Agent"; +BEGIN { + if (eval { local $SIG{__DIE__}; require Log::Agent; 1 }) { + Log::Agent->import; + } + # + # Use of Log::Agent is optional. If it hasn't imported these subs then + # provide a fallback implementation. + # + if (!exists &logcroak) { + require Carp; + *logcroak = sub { + Carp::croak(@_); + }; + } + if (!exists &logcarp) { + require Carp; + *logcarp = sub { + Carp::carp(@_); + }; + } } -require Carp; - # # They might miss :flock in Fcntl # @@ -57,28 +65,12 @@ sub CLONE { Storable::init_perinterp(); } -# Can't Autoload cleanly as this clashes 8.3 with &retrieve -sub retrieve_fd { &fd_retrieve } # Backward compatibility - # By default restricted hashes are downgraded on earlier perls. $Storable::downgrade_restricted = 1; $Storable::accept_future_minor = 1; -bootstrap Storable; -1; -__END__ -# -# Use of Log::Agent is optional. If it hasn't imported these subs then -# Autoloader will kindly supply our fallback implementation. -# - -sub logcroak { - Carp::croak(@_); -} -sub logcarp { - Carp::carp(@_); -} +XSLoader::load('Storable', $Storable::VERSION); # # Determine whether locking is possible, but only when needed. @@ -116,8 +108,10 @@ EOM } sub file_magic { + require IO::File; + my $file = shift; - my $fh = new FileHandle; + my $fh = IO::File->new; open($fh, "<". $file) || die "Can't open '$file': $!"; binmode($fh); defined(sysread($fh, my $buf, 32)) || die "Can't read from '$file': $!"; @@ -151,14 +145,14 @@ sub read_magic { $net_order = 0; } else { - $net_order = ord(substr($buf, 0, 1, "")); - my $major = $net_order >> 1; + $buf =~ s/(.)//s; + my $major = (ord $1) >> 1; return undef if $major > 4; # sanity (assuming we never go that high) $info{major} = $major; - $net_order &= 0x01; + $net_order = (ord $1) & 0x01; if ($major > 1) { - return undef unless length($buf); - my $minor = ord(substr($buf, 0, 1, "")); + return undef unless $buf =~ s/(.)//s; + my $minor = ord $1; $info{minor} = $minor; $info{version} = "$major.$minor"; $info{version_nv} = sprintf "%d.%03d", $major, $minor; @@ -171,17 +165,16 @@ sub read_magic { $info{netorder} = $net_order; unless ($net_order) { - return undef unless length($buf); - my $len = ord(substr($buf, 0, 1, "")); + return undef unless $buf =~ s/(.)//s; + my $len = ord $1; return undef unless length($buf) >= $len; return undef unless $len == 4 || $len == 8; # sanity - $info{byteorder} = substr($buf, 0, $len, ""); - $info{intsize} = ord(substr($buf, 0, 1, "")); - $info{longsize} = ord(substr($buf, 0, 1, "")); - $info{ptrsize} = ord(substr($buf, 0, 1, "")); + @info{qw(byteorder intsize longsize ptrsize)} + = unpack "a${len}CCC", $buf; + (substr $buf, 0, $len + 3) = ''; if ($info{version_nv} >= 2.002) { - return undef unless length($buf); - $info{nvsize} = ord(substr($buf, 0, 1, "")); + return undef unless $buf =~ s/(.)//s; + $info{nvsize} = ord $1; } } $info{hdrsize} = $buflen - length($buf); @@ -408,6 +401,8 @@ sub fd_retrieve { return $self; } +sub retrieve_fd { &fd_retrieve } # Backward compatibility + # # thaw # @@ -910,12 +905,12 @@ This returns the file format version as number. It is a string like "2.007". This value is suitable for numeric comparisons. The constant function C returns a comparable -number that represent the highest file version number that this -version of Storable fully support (but see discussion of +number that represents the highest file version number that this +version of Storable fully supports (but see discussion of C<$Storable::accept_future_minor> above). The constant C function returns what file version is written and might be less than C in some -configuations. +configurations. =item C, C