X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FStorable%2FStorable.pm;h=e1a72f6a83be707ab3a23fb539e804ab33a60535;hb=2cc1b180444ab1e2ac675ff3e9f78a123bc70c80;hp=3ea8794a749bca617c208eeb1953dfad40c79391;hpb=ee0f7aac1ecaadc3d1d4426e1767e2fd6044b164;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/Storable/Storable.pm b/ext/Storable/Storable.pm index 3ea8794..e1a72f6 100644 --- a/ext/Storable/Storable.pm +++ b/ext/Storable/Storable.pm @@ -1,4 +1,3 @@ -# $Id: Storable.pm,v 1.0.1.13 2001/12/01 13:34:49 ram Exp $ # # Copyright (c) 1995-2000, Raphael Manfredi # @@ -22,7 +21,7 @@ package Storable; @ISA = qw(Exporter DynaLoader); use AutoLoader; use vars qw($canonical $forgive_me $VERSION); -$VERSION = '2.03'; +$VERSION = '2.07'; *AUTOLOAD = \&AutoLoader::AUTOLOAD; # Grrr... # @@ -362,6 +361,9 @@ sub thaw { return $self; } +1; +__END__ + =head1 NAME Storable - persistence for Perl data structures @@ -510,6 +512,22 @@ creating lookup tables for complicated queries. Canonical order does not imply network order; those are two orthogonal settings. +=head1 CODE REFERENCES + +Since Storable version 2.05, CODE references may be serialized with +the help of L. To enable this feature, set +C<$Storable::Deparse> to a true value. To enable deserializazion, +C<$Storable::Eval> should be set to a true value. Be aware that +deserialization is done through C, which is dangerous if the +Storable file contains malicious data. You can set C<$Storable::Eval> +to a subroutine reference which would be used instead of C. See +below for an example using a L compartment for deserialization +of CODE references. + +If C<$Storable::Deparse> and/or C<$Storable::Eval> are set to false +values, then the value of C<$Storable::forgive_me> (see below) is +respected while serializing and deserializing. + =head1 FORWARD COMPATIBILITY This release of Storable can be used on a newer version of Perl to @@ -785,6 +803,28 @@ which prints (on my machine): Blue is still 0.100000 Serialization of %color is 102 bytes long. +Serialization of CODE references and deserialization in a safe +compartment: + +=for example begin + + use Storable qw(freeze thaw); + use Safe; + use strict; + my $safe = new Safe; + # because of opcodes used in "use strict": + $safe->permit(qw(:default require)); + local $Storable::Deparse = 1; + local $Storable::Eval = sub { $safe->reval($_[0]) }; + my $serialized = freeze(sub { 42 }); + my $code = thaw($serialized); + $code->() == 42; + +=for example end + +=for example_testing + is( $code->(), 42 ); + =head1 WARNING If you're using references as keys within your hash tables, you're bound @@ -813,9 +853,9 @@ your data. There is no slowdown on retrieval. =head1 BUGS -You can't store GLOB, CODE, FORMLINE, etc.... If you can define -semantics for those operations, feel free to enhance Storable so that -it can deal with them. +You can't store GLOB, FORMLINE, etc.... If you can define semantics +for those operations, feel free to enhance Storable so that it can +deal with them. The store functions will C if they run into such references unless you set C<$Storable::forgive_me> to some C value. In that