704df3
From fd2e79041c553c1220c6eca796293873246c5682 Mon Sep 17 00:00:00 2001
704df3
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
704df3
Date: Wed, 6 May 2015 09:39:53 +0200
704df3
Subject: [PATCH] Upgrade to 2.53
704df3
MIME-Version: 1.0
704df3
Content-Type: text/plain; charset=UTF-8
704df3
Content-Transfer-Encoding: 8bit
704df3
704df3
Signed-off-by: Petr Písař <ppisar@redhat.com>
704df3
---
704df3
 ChangeLog         |  2 +-
704df3
 MANIFEST          |  3 +++
704df3
 Storable.pm       |  6 +++---
704df3
 t/attach.t        | 42 ++++++++++++++++++++++++++++++++++++
704df3
 t/attach_errors.t |  2 +-
704df3
 t/canonical.t     |  2 +-
704df3
 t/code.t          |  2 +-
704df3
 t/leaks.t         | 34 +++++++++++++++++++++++++++++
704df3
 t/tied_store.t    | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
704df3
 t/utf8.t          |  6 ++++--
704df3
 10 files changed, 154 insertions(+), 9 deletions(-)
704df3
 create mode 100644 t/attach.t
704df3
 create mode 100644 t/leaks.t
704df3
 create mode 100644 t/tied_store.t
704df3
704df3
diff --git a/ChangeLog b/ChangeLog
704df3
index 4df921e..cbfdbab 100644
704df3
--- a/ChangeLog
704df3
+++ b/ChangeLog
704df3
@@ -209,7 +209,7 @@ Fri Jun  7 23:55:41 BST 2002   Nicholas Clark
704df3
 	The bug was introduced as development perl change 16442 (on
704df3
 	2002/05/07), so has been present since 2.00.
704df3
 	Patches to introduce more regression tests to reduce the chance of
704df3
-	a reoccurence of this sort of goof are always welcome.
704df3
+	a reoccurrence of this sort of goof are always welcome.
704df3
 	
704df3
 Thu May 30 20:31:08 BST 2002   Nicholas Clark <nick@ccl4.org>
704df3
 
704df3
diff --git a/MANIFEST b/MANIFEST
704df3
index 84b72f1..2f5b725 100644
704df3
--- a/MANIFEST
704df3
+++ b/MANIFEST
704df3
@@ -9,6 +9,7 @@ ppport.h
704df3
 README
704df3
 Storable.pm
704df3
 Storable.xs
704df3
+t/attach.t
704df3
 t/attach_errors.t
704df3
 t/attach_singleton.t
704df3
 t/blessed.t
704df3
@@ -33,6 +34,7 @@ t/HAS_OVERLOAD.pm
704df3
 t/integer.t
704df3
 t/interwork56.t
704df3
 t/just_plain_nasty.t
704df3
+t/leaks.t
704df3
 t/lock.t
704df3
 t/make_56_interwork.pl
704df3
 t/make_downgrade.pl
704df3
@@ -51,6 +53,7 @@ t/threads.t
704df3
 t/tied.t
704df3
 t/tied_hook.t
704df3
 t/tied_items.t
704df3
+t/tied_store.t
704df3
 t/utf8.t
704df3
 t/utf8hash.t
704df3
 t/weak.t
704df3
diff --git a/Storable.pm b/Storable.pm
704df3
index 839c1d1..9d8b621 100644
704df3
--- a/Storable.pm
704df3
+++ b/Storable.pm
704df3
@@ -22,7 +22,7 @@ package Storable; @ISA = qw(Exporter);
704df3
 
704df3
 use vars qw($canonical $forgive_me $VERSION);
704df3
 
704df3
-$VERSION = '2.51';
704df3
+$VERSION = '2.53';
704df3
 
704df3
 BEGIN {
704df3
     if (eval { local $SIG{__DIE__}; require Log::Agent; 1 }) {
704df3
@@ -1088,8 +1088,8 @@ deal with them.
704df3
 
704df3
 The store functions will C<croak> if they run into such references
704df3
 unless you set C<$Storable::forgive_me> to some C<TRUE> value. In that
704df3
-case, the fatal message is turned in a warning and some
704df3
-meaningless string is stored instead.
704df3
+case, the fatal message is converted to a warning and some meaningless
704df3
+string is stored instead.
704df3
 
704df3
 Setting C<$Storable::canonical> may not yield frozen strings that
704df3
 compare equal due to possible stringification of numbers. When the
704df3
diff --git a/t/attach.t b/t/attach.t
704df3
new file mode 100644
704df3
index 0000000..5ffdae5
704df3
--- /dev/null
704df3
+++ b/t/attach.t
704df3
@@ -0,0 +1,42 @@
704df3
+#!./perl -w
704df3
+#
704df3
+# This file tests that Storable correctly uses STORABLE_attach hooks
704df3
+
704df3
+sub BEGIN {
704df3
+	unshift @INC, 't';
704df3
+	unshift @INC, 't/compat' if $] < 5.006002;
704df3
+	require Config; import Config;
704df3
+	if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
704df3
+		print "1..0 # Skip: Storable was not built\n";
704df3
+		exit 0;
704df3
+	}
704df3
+}
704df3
+
704df3
+use Test::More tests => 3;
704df3
+use Storable ();
704df3
+
704df3
+{
704df3
+	my $destruct_cnt = 0;
704df3
+	my $obj = bless {data => 'ok'}, 'My::WithDestructor';
704df3
+	my $target = Storable::thaw( Storable::freeze( $obj ) );
704df3
+	is( $target->{data}, 'ok', 'We got correct object after freeze/thaw' );
704df3
+	is( $destruct_cnt, 0, 'No tmp objects created by Storable' );
704df3
+	undef $obj;
704df3
+	undef $target;
704df3
+	is( $destruct_cnt, 2, 'Only right objects destroyed at the end' );
704df3
+
704df3
+	package My::WithDestructor;
704df3
+
704df3
+	sub STORABLE_freeze {
704df3
+		my ($self, $clone) = @_;
704df3
+		return $self->{data};
704df3
+	}
704df3
+
704df3
+	sub STORABLE_attach {
704df3
+		my ($class, $clone, $string) = @_;
704df3
+		return bless {data => $string}, 'My::WithDestructor';
704df3
+	}
704df3
+
704df3
+	sub DESTROY { $destruct_cnt++; }
704df3
+}
704df3
+
704df3
diff --git a/t/attach_errors.t b/t/attach_errors.t
704df3
index c163ca0..6cebd97 100644
704df3
--- a/t/attach_errors.t
704df3
+++ b/t/attach_errors.t
704df3
@@ -234,7 +234,7 @@ use Storable ();
704df3
 	isa_ok( $thawed->[1], 'My::GoodAttach::MultipleReferences' );
704df3
 
704df3
 	is($thawed->[0], $thawed->[1], 'References to the same object are attached properly');
704df3
-	is($thawed->[1]{id}, $obj->{id}, 'Object with multiple references attchached properly');
704df3
+	is($thawed->[1]{id}, $obj->{id}, 'Object with multiple references attached properly');
704df3
 
704df3
     package My::GoodAttach::MultipleReferences;
704df3
 
704df3
diff --git a/t/canonical.t b/t/canonical.t
704df3
index 23e012f..35046de 100644
704df3
--- a/t/canonical.t
704df3
+++ b/t/canonical.t
704df3
@@ -34,7 +34,7 @@ $maxarraysize = 100;
704df3
 
704df3
 eval { require Digest::MD5; };
704df3
 $gotmd5 = !$@;
704df3
-diag "Will use Digest::MD5" if $gotmd5;
704df3
+note "Will use Digest::MD5" if $gotmd5;
704df3
 
704df3
 # Use Data::Dumper if debugging and it is available to create an ASCII dump
704df3
 
704df3
diff --git a/t/code.t b/t/code.t
704df3
index c383142..7fc40ba 100644
704df3
--- a/t/code.t
704df3
+++ b/t/code.t
704df3
@@ -102,7 +102,7 @@ is($thawed->{"b"}->(), "JAPH");
704df3
 $freezed = freeze $obj[2];
704df3
 $thawed  = thaw $freezed;
704df3
 
704df3
-is($thawed->(), 42);
704df3
+is($thawed->(), (ord "A") == 193 ? -118 : 42);
704df3
 
704df3
 ######################################################################
704df3
 
704df3
diff --git a/t/leaks.t b/t/leaks.t
704df3
new file mode 100644
704df3
index 0000000..06360d6
704df3
--- /dev/null
704df3
+++ b/t/leaks.t
704df3
@@ -0,0 +1,34 @@
704df3
+#!./perl
704df3
+
704df3
+use Test::More;
704df3
+use Storable ();
704df3
+BEGIN {
704df3
+eval "use Test::LeakTrace";
704df3
+plan 'skip_all' => 'Test::LeakTrace required for this tests' if $@;
704df3
+}
704df3
+plan 'tests' => 1;
704df3
+
704df3
+{
704df3
+    my $c = My::Simple->new;
704df3
+    my $d;
704df3
+    my $freezed = Storable::freeze($c);
704df3
+    no_leaks_ok
704df3
+    {
704df3
+        $d = Storable::thaw($freezed);
704df3
+        undef $d;
704df3
+    };
704df3
+
704df3
+    package My::Simple;
704df3
+    sub new {
704df3
+        my ($class, $arg) = @_;
704df3
+        bless {t=>$arg}, $class;
704df3
+    }
704df3
+    sub STORABLE_freeze {
704df3
+        return "abcderfgh";
704df3
+    }
704df3
+    sub STORABLE_attach {
704df3
+        my ($class, $c, $serialized) = @_;
704df3
+        return $class->new($serialized);
704df3
+    }
704df3
+}
704df3
+
704df3
diff --git a/t/tied_store.t b/t/tied_store.t
704df3
new file mode 100644
704df3
index 0000000..c657f95
704df3
--- /dev/null
704df3
+++ b/t/tied_store.t
704df3
@@ -0,0 +1,64 @@
704df3
+#!./perl
704df3
+
704df3
+sub BEGIN {
704df3
+    unshift @INC, 't';
704df3
+    unshift @INC, 't/compat' if $] < 5.006002;
704df3
+    require Config; import Config;
704df3
+    if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
704df3
+        print "1..0 # Skip: Storable was not built\n";
704df3
+        exit 0;
704df3
+    }
704df3
+}
704df3
+
704df3
+use Storable ();
704df3
+use Test::More tests => 3;
704df3
+
704df3
+our $f;
704df3
+
704df3
+package TIED_HASH;
704df3
+
704df3
+sub TIEHASH { bless({}, $_[0]) }
704df3
+
704df3
+sub STORE {
704df3
+	$f = Storable::freeze(\$_[2]);
704df3
+	1;
704df3
+}
704df3
+
704df3
+package TIED_ARRAY;
704df3
+
704df3
+sub TIEARRAY { bless({}, $_[0]) }
704df3
+
704df3
+sub STORE {
704df3
+	$f = Storable::freeze(\$_[2]);
704df3
+	1;
704df3
+}
704df3
+
704df3
+package TIED_SCALAR;
704df3
+
704df3
+sub TIESCALAR { bless({}, $_[0]) }
704df3
+
704df3
+sub STORE {
704df3
+	$f = Storable::freeze(\$_[1]);
704df3
+	1;
704df3
+}
704df3
+
704df3
+package main;
704df3
+
704df3
+my($s, @a, %h);
704df3
+tie $s, "TIED_SCALAR";
704df3
+tie @a, "TIED_ARRAY";
704df3
+tie %h, "TIED_HASH";
704df3
+
704df3
+$f = undef;
704df3
+$s = 111;
704df3
+is $f, Storable::freeze(\111);
704df3
+
704df3
+$f = undef;
704df3
+$a[3] = 222;
704df3
+is $f, Storable::freeze(\222);
704df3
+
704df3
+$f = undef;
704df3
+$h{foo} = 333;
704df3
+is $f, Storable::freeze(\333);
704df3
+
704df3
+1;
704df3
diff --git a/t/utf8.t b/t/utf8.t
704df3
index fd20ef6..a8dd6cd 100644
704df3
--- a/t/utf8.t
704df3
+++ b/t/utf8.t
704df3
@@ -32,8 +32,10 @@ is($x, ${thaw freeze \$x});
704df3
 $x = join '', map {chr $_} (0..1023);
704df3
 is($x, ${thaw freeze \$x});
704df3
 
704df3
-# Char in the range 127-255 (probably) in utf8
704df3
-$x = chr (175) . chr (256);
704df3
+# Char in the range 127-255 (probably) in utf8.  This just won't work for
704df3
+# EBCDIC for early Perls.
704df3
+$x = ($] lt 5.007_003) ? chr(175) : chr(utf8::unicode_to_native(175))
704df3
+   . chr (256);
704df3
 chop $x;
704df3
 is($x, ${thaw freeze \$x});
704df3
 
704df3
-- 
704df3
2.1.0
704df3