Skip to content

Instantly share code, notes, and snippets.

@domm
Created July 1, 2010 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save domm/460521 to your computer and use it in GitHub Desktop.
Save domm/460521 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Scalar::Util qw(refaddr);
use Test::More;use Test::Exception;
use KiokuDB;
BEGIN {
plan skip_all => "DBD::SQLite are required" unless eval { require DBI; require DBD::SQLite };
}
{
package MyApp::DB::Result::Foo;
use base qw(DBIx::Class::Core);
__PACKAGE__->load_components(qw(KiokuDB));
__PACKAGE__->table('foo');
__PACKAGE__->add_columns(qw(id name object));
__PACKAGE__->set_primary_key('id');
__PACKAGE__->kiokudb_column('object');
package MyApp::DB;
use base qw(DBIx::Class::Schema);
__PACKAGE__->load_components(qw(Schema::KiokuDB));
__PACKAGE__->register_class( Foo => qw(MyApp::DB::Result::Foo));
package Foo;
use Moose;
has name => ( isa => "Str", is => "ro" );
has obj => ( isa => "Object", is => "ro", weak_ref => 1 );
__PACKAGE__->meta->make_immutable;
}
my $schema = MyApp::DB->connect('dbi:SQLite:dbname=:memory:');
my $dir = $schema->kiokudb_handle;
$dir->txn_do( scope => 1, body => sub {
$dir->insert( foo => my $obj = Foo->new );
$schema->resultset("Foo")->create({ id => 1, name => "foo", object => $obj });
my $row = $dir->backend->schema->resultset("Foo")->create({ id => 2, name => "foo", object => "foo" });
isa_ok( $row->object, 'Foo', 'inflated from constructor' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment