Subject: | odd interaction with Storable |
Perl version: v5.8.0 built for i386-linux-thread-multi
URI version: 1.25
on Linux 2.4.22, Debian testing dist
The script at the end of this message gives me an error:
Cannot restore overloading on SCALAR(0x821ed94) (package URI::http) at ../../lib/Storable.pm (autosplit into ../../lib/auto/Storable/_retrieve.al) line 323, at ack.pl line 15
unless I add a STORABLE_freeze and STORABLE_thaw handler for the underlying URI::* objects. I have attached a patch to URI::_query that appears to allow objects that contain URI objects to be Storable serialized. It's likely not the ideal way to fix this problem, but appears to do the job reliably.
#!/usr/bin/perl
use strict;
use warnings;
if($ARGV[0] eq 's') {
use URI;
use Storable;
my $a = {
u => new URI('http://search.cpan.org/'),
};
store $a, 'data.dat';
} else {
use Storable;
use Data::Dumper;
my $a = retrieve 'data.dat';
print Dumper([$a]);
}
diff -Naur URI-1.25/URI/_query.pm URI-1.25fix/URI/_query.pm
--- URI-1.25/URI/_query.pm 2003-08-05 07:22:03.000000000 -0700
+++ URI-1.25fix/URI/_query.pm 2003-09-29 18:15:37.000000000 -0700
@@ -67,4 +67,13 @@
# Some URI::URL compatibility stuff
*equery = \&query;
+sub STORABLE_freeze {
+ my($self, $cloning) = @_;
+ return $$self;
+}
+sub STORABLE_thaw {
+ my($self, $clonging, $str) = @_;
+ $$self = $str;
+}
+
1;