[CDBI] using closures for inflate and deflate

Brian Phillips bpphillips at gmail.com
Wed Nov 2 19:46:49 GMT 2005


I recently discovered when I upgraded Class::DBI from v3.0.1 to v3.0.11 that
some of my inflate/deflate methods no longer work. It appears that beginning
in version 3.0.9, the _extend_meta method in Class/DBI.pm uses Storable to
do a dclone on the meta info. I'm not sure of the reasoning behind this
apart from what's in the Changes file:

Fixed bug with shared meta_info (Will Ross)

Up to now, I've used the inflate/deflate functionality occasionaly as a
closure. For example (very contrived):

my $secret = "password";
__PACKAGE__->has_a(my_password_col => "My::Blowfish",
inflate => sub { My::Blowfish->new(shift,$secret) },
deflate => "encrypt"
);

This kind of functionality stopped working because once that anonymous sub
(closure) was run through Storable::dclone, it no longer had access to the
$secret variable.

I realize there's a million ways to do the above differently but it becomes
more challenging when I want to auto-generate a bunch of 'has_a' columns. It
was very nice to be able to create those anonymous subs on the fly without
having to do a string evaluation or specify every variable explicitly within
the sub itself.

Is this just Bad Practice(R) to do this kind of thing? Is there any hope
that dclone will be dropped from that _extend_meta method? Should I just
create my own select and after_set_$column triggers rather than using has_a
for non-"table relationship" relationships?

Thanks for any suggestions/feedback you might have,
Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digitalcraftsmen.net/mailman/private/classdbi/attachments/20051102/67d6173a/attachment.htm


More information about the ClassDBI mailing list