[CDBI] Multiple inflate CODE references

Kevin White kevin at theconfused.co.uk
Fri Oct 7 10:52:01 BST 2005

Hi Folks,

I am new here so forgive me if this has come up before, I couldn't  
find anything in the archives so I thought I would post and get some  
thoughts. I have a table structure with the following has_a  

__PACKAGE__->has_a( expire_date => 'Time::Piece',
     inflate => sub { Time::Piece->strptime( shift, "%Y-%m-%d" ) },
     deflate => 'ymd',

__PACKAGE__->has_a( start_date => 'Time::Piece',
     inflate => sub { Time::Piece->strptime( shift, "%Y-%m-%d" ) },
     deflate => 'ymd',

(Code is unashamedly ripped from the CDBI docs)

Trouble was I kept getting the following:

Can't store CODE items at /Library/Perl/5.8.6/Class/DBI.pm line 1039,  
<IN> line 79.

The line in questions is:

     my %hash = %{ dclone($class->__meta_info || {}) };

So what was happening is the first code reference went in with no  
problem as there was no attempt to serialize the object but the  
second has_a tried to serialize the object and fails cause you can't  
store CODE references with Storable.... unless you add the following:

$Storable::Deparse = 1;
$Storable::Eval = 1;

a la http://search.cpan.org/~ams/Storable-2.15/ 

Which I did and all things seem to work well now.

My question is, is there a reason that doing this is a bad idea?

Thanks for any thoughts.


More information about the ClassDBI mailing list