[Dbix-class] Re: Using Storable with DBIx::Class - Can't locate object method "result_source_instance"

Bill Moseley moseley at hank.org
Thu Oct 1 01:41:41 GMT 2009


On Wed, Sep 30, 2009 at 3:00 PM, Wallace Reis <reis.wallace at gmail.com>wrote:

>
> > Unable to restore schema at ../../lib/Storable.pm (autosplit into
> > ../../lib/auto/Storable/thaw.al) line 415
> > calling ->cds on deserialized object
> > Can't call method "source" on an undefined value at
> > /usr/local/share/perl/5.10.0/DBIx/Class/R
>
> The error message is clever in 0.08112. You need to 'freeze' and
> 'thaw' your dbic row. Look at DBIC::Schema docs about it.
>

Well, I wonder about that message.   That would have me think that the
approach would be to do a Storable round trip like:

$schema->thaw( $schema->freeze( $artist ) );

And then a common use case might be to store an object in a session hash, as
with Catalyst.  Are you saying that the recommended approach is this?

$c->session->{foo} =3D $schema->freeze( $object );

And then later

$object =3D $schema->thaw( $c->session->{foo} );

Which ends up running through Storable twice.

I wonder if that message should not point to the
DBIx::Class::ResultSourceHandle docs (which is where it is generated from).
There it would point out that you can set

$DBIx::Class::ResultSourceHandle::thaw_schema =3D $schema;

before thawing and then the Storable hooks will work.  There it also
recommends using $schema->thaw, but then it's back to pre-serializing,
unless I'm missing the expected use.

Of course, a global $schema is sometimes not desirable.  Perhaps allowing
thaw_schema to be a coderef might be useful as then you could inspect the
deserialized object and have a chance at selecting and returning the correct
schema.


Then, there's  DBIx::Class::Serialize::Storable with the synopsis:

    my $cd =3D $schema->resultset('CD')->find(12);
    # if the cache uses Storable, this will work automatically
    $cache->set($cd->ID, $cd);

What does that do?  Freezing isn't the issue.  Plus, seems that $cd freezes
and thaws fine without it.  And that synopsis isn't showing the
$cache->get.  I guess I'm missing the point of that component.



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090930/058=
ffcab/attachment.htm


More information about the DBIx-Class mailing list