perl - Why will Storable load some classes, but not others? -


i'm having problem frozen objects in storable. when storable thaws object, it's supposed load class. true, isn't. here's sample code...

#!/usr/bin/env perl -l  use strict; use warnings;  use storable;  if( fork ) { } else {     print "in child.";      # load modules in child process parent 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 done."; print "------------------------------";  print "datetime not loaded" if !$inc{"datetime.pm"}; $datetime = storable::retrieve("/tmp/uri.out"); print $inc{"datetime.pm"}; print $datetime->year;  print "foo not loaded" if !$inc{"foo.pm"}; $obj = storable::retrieve("/tmp/tb2.out"); print $inc{"foo.pm"}; print $obj->id; 

and quite simple foo.pm.

$ cat lib/foo.pm  package foo;  use strict; use vars qw($version); $version = "1.60";  sub new {     $class = shift;      return bless { foo => 23 }, $class; }  sub id { 42 }  1; 

i program...

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 done. ------------------------------ datetime 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 not loaded use of uninitialized value in print @ /users/schwern/tmp/test.plx line 38.  can't locate object method "id" via package "foo" @ /users/schwern/tmp/test.plx line 39. 

as can see, happily load datetime not foo module. object restored, foo.pm not loaded. have problem storable 2.34 , perl 5.16.2.

can people repeat problem? there solution?

datetime defines storable_freeze , storable_thaw. 1 deduce storable notes whether class used hook freeze , looks corresponding hook thaw it. module loading part of hook logic not invoked foo.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -