Alternatives to storing Moose object using Apache::Session with CODE references

Posted by Hartmut Behrens on Stack Overflow See other posts from Stack Overflow or by Hartmut Behrens
Published on 2010-06-18T13:08:57Z Indexed on 2010/06/18 13:13 UTC
Read the original article Hit count: 439

Filed under:
|
|

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 ?

© Stack Overflow or respective owner

Related posts about perl

Related posts about moose