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

Bill Moseley moseley at hank.org
Wed Sep 30 16:10:13 GMT 2009


$VERSION =3D '0.08111';

Ok, starting simple, what's the correct way to store and retrieve dbic row
objects from Storable?

#!/usr/bin/perl
use warnings;
use strict;
use Storable;
use MyApp;

my $schema =3D MyApp->connect({ dsn =3D> 'dbi:Pg:database=3Dmusic' });

my $artist =3D $schema->resultset( 'Artist' )->find( 1 );
my @cds =3D $artist->cds;

warn "storing\n";
store { artist =3D> $artist, }, 'stored';

warn "retrieve\n";
my $h =3D retrieve 'stored';

warn "calling ->cds on deserialized object\n";
$h->{artist}->cds;

Results in:

storing
retrieve
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


My Artist class uses this base class, although I get the same thing
regardless of including
Serialize::Storable.

package MyApp::Result;
use strict;
use warnings;
use base qw( DBIx::Class );

__PACKAGE__->load_components(qw/
    Serialize::Storable
    InflateColumn::DateTime
    Core
/);

1;


FYI, here's the Artist class.

package MyApp::Result::Artist;

use strict;
use warnings;

use base 'MyApp::Result';

#__PACKAGE__->load_components("InflateColumn::DateTime", "Core");
__PACKAGE__->table("artist");
__PACKAGE__->add_columns(
  "id",
  {
    data_type =3D> "integer",
    default_value =3D> "nextval('artist_id_seq'::regclass)",
    is_auto_increment =3D> 1,
    is_nullable =3D> 0,
    size =3D> 4,
  },
  "name",
  {
    data_type =3D> "text",
    default_value =3D> undef,
    is_nullable =3D> 1,
    size =3D> undef,
  },
  "label",
  {
    data_type =3D> "integer",
    default_value =3D> undef,
    is_foreign_key =3D> 1,
    is_nullable =3D> 0,
    size =3D> 4,
  },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to("label", "MyApp::Result::Label", { id =3D> "label" =
});
__PACKAGE__->has_many("cds", "MyApp::Result::Cd", { "foreign.artist" =3D> "
self.id" });


# Created by DBIx::Class::Schema::Loader v0.04999_08 @ 2009-09-21 11:25:54
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:VpcwTJEGCmz+LZCDMjwqqw


# You can replace this text with custom content, and it will be preserved on
regeneration
1;


-- =

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


More information about the DBIx-Class mailing list