Storable で凍結されたオブジェクトに問題があります。Storable がオブジェクトを解凍するとき、クラスをロードすることになっています。これは通常正しいですが、そうでない場合もあります。ここにいくつかのサンプルコードがあります...
#!/usr/bin/env perl -l
use strict;
use warnings;
use Storable;
if( fork ) {
}
else {
print "In child.";
# Load modules in a child process so the parent does not have them loaded
require Foo;
print $INC{"Foo.pm"};
print $Foo::VERSION;
Storable::store( Foo->new("http://example.com"), "/tmp/tb2.out" );
require DateTime;
print $INC{"DateTime.pm"};
Storable::store( DateTime->new(year => 2009), "/tmp/uri.out" );
exit;
}
wait;
print "Child is done.";
print "------------------------------";
print "DateTime is not loaded" if !$INC{"DateTime.pm"};
my $datetime = Storable::retrieve("/tmp/uri.out");
print $INC{"DateTime.pm"};
print $datetime->year;
print "Foo is not loaded" if !$INC{"Foo.pm"};
my $obj = Storable::retrieve("/tmp/tb2.out");
print $INC{"Foo.pm"};
print $obj->id;
そしてとてもシンプルな Foo.pm.
$ cat lib/Foo.pm
package Foo;
use strict;
use vars qw($VERSION);
$VERSION = "1.60";
sub new {
my $class = shift;
return bless { foo => 23 }, $class;
}
sub id { 42 }
1;
私はそのプログラムから取得します...
In child.
lib/Foo.pm
1.60
/Users/schwern/perl5/perlbrew/perls/perl-5.16.2-threads/lib/site_perl/5.16.2/darwin-thread-multi-2level/DateTime.pm
Child is done.
------------------------------
DateTime is not loaded
/Users/schwern/perl5/perlbrew/perls/perl-5.16.2-threads/lib/site_perl/5.16.2/darwin-thread-multi-2level/DateTime.pm
2009
Foo is not loaded
Use of uninitialized value in print at /Users/schwern/tmp/test.plx line 38.
Can't locate object method "id" via package "Foo" at /Users/schwern/tmp/test.plx line 39.
ご覧のとおり、DateTime は問題なくロードされますが、私の Foo モジュールはロードされません。オブジェクトは復元されますが、Foo.pm はロードされません。Storable 2.34 と perl 5.16.2 でこの問題が発生しました。
人々はこの問題を繰り返すことができますか? 解決策はありますか?