lom has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I have a problem while using CGI::Session, when I try to store an object. After a few tests, I've isolated the problem.
I have got a class (Md), which contains a method param().
When I dump (data::Dumper) an object of this class, when I 'thaw' it with Safe (which basically do sandbox'ed eval), I get an object from the right class, but which can not execute param();
See following code for explanation:
#!/usr/bin/perl use strict; use Data::Dumper; use Safe; package Md; sub new {bless {'plop' => 'coin'}, $_[0]}; sub param {return $_[0]->{$_[1]};} package main; #Object and dump creation my $md = Md->new(); my $dump = Dumper($md); #'eval'ed dump my $mde = eval($dump); print defined $mde ? "Defined" : "undef"; # => print undef, bad #Dump 'Safe' eval my $mdr = Safe->new->reval( $dump ); print defined $mdr ? "Defined" : "undef"; # => print defined, good print $mdr->can('param') ? "yes" : "No"; # => print No. Why?
Why a Md object ($mdr) cannot execute one of the Md methods?
Notes:
I noticed that by using $Data::Dumper::Terse or without 'use strict' it is possible to restore the object as intended, but the problem is hidden inside CGI::Session, I thus cannot use these solutions.
Thanks for you help
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::Session cannot read data from Data::Dumper
by perrin (Chancellor) on Oct 31, 2007 at 13:37 UTC | |
by lom (Sexton) on Oct 31, 2007 at 14:32 UTC | |
|
Re: CGI::Session cannot read data from Data::Dumper
by !1 (Hermit) on Oct 31, 2007 at 22:05 UTC | |
by lom (Sexton) on Nov 01, 2007 at 11:27 UTC | |
by !1 (Hermit) on Nov 01, 2007 at 13:21 UTC | |
by lom (Sexton) on Nov 02, 2007 at 08:32 UTC |