Alternatives to storing Moose object using Apache::Session with CODE references
- by Hartmut Behrens
I have a Moose class that i would like to store using Apache::Session::File.
However, Apache::Session::File by default will not store it and instead i get the error message:
(in cleanup) Can't store CODE items at blib\lib\Storable.pm (autosplit into blib\lib\auto\Storable\_freeze.al)...
This problem can be circumvented by setting
$Storable::Deparse = 1;
$Storable::Eval = 1;
in order to allow CODE references to be serialized.
The offending method in the Moose class is listed below, which retrieves a column from a mysql database:
sub _build_cell_generic {
my ($self,$col) = @_;
my $sth = $self->call_dbh('prepare','select '.$col.' from '.$self->TABLE.' where CI = ? and LAC = ? and IMPORTDATE = ?');
$sth->execute($self->CI,$self->LAC,$self->IMPORTDATE);
my $val = $sth->fetchrow_array;
$sth->finish;
return defined $val ? $val : undef;
}
So presumably the dbh object (isa DBIx::Connector) contains CODE references.
Is there a better alternative in order to allow serialization of this Moose class than setting $Storable::Deparse and $Storable::Eval ?