8 use Storable qw(dclone freeze nfreeze thaw);
10 my $schema = DBICTest->init_schema();
11 my $orig_debug = $schema->storage->debug;
14 dclone_method => sub { return $schema->dclone($_[0]) },
15 dclone_func => sub { return dclone($_[0]) },
16 "freeze/thaw_method" => sub {
17 my $ice = $schema->freeze($_[0]);
18 return $schema->thaw($ice);
20 "freeze/thaw_func" => sub {
23 "nfreeze/thaw_func" => sub {
28 plan tests => (17 * keys %stores);
30 for my $name (keys %stores) {
31 my $store = $stores{$name};
34 my $artist = $schema->resultset('Artist')->find(1);
36 # Test that the procedural versions will work if there's a registered
37 # schema as with CDBICompat objects and that the methods work
39 if( $name =~ /func/ ) {
40 $artist->result_source_instance->schema($schema);
41 DBICTest::CD->result_source_instance->schema($schema);
44 $artist->result_source_instance->schema(undef);
45 DBICTest::CD->result_source_instance->schema(undef);
48 lives_ok { $copy = $store->($artist) } "serialize row object lives: $name";
49 is_deeply($copy, $artist, "serialize row object works: $name");
51 my $cd_rs = $artist->search_related("cds");
53 # test that a live result source can be serialized as well
54 is( $cd_rs->count, 3, '3 CDs in database');
55 ok( $cd_rs->next, 'Advance cursor' );
58 $copy = $store->($cd_rs);
62 "serialize resultset works: $name",
64 } "serialize resultset lives: $name";
66 # Test that an object with a related_resultset can be serialized.
67 ok $artist->{related_resultsets}, 'has key: related_resultsets';
69 lives_ok { $copy = $store->($artist) } "serialize row object with related_resultset lives: $name";
70 for my $key (keys %$artist) {
71 next if $key eq 'related_resultsets';
72 next if $key eq '_inflated_column';
73 is_deeply($copy->{$key}, $artist->{$key},
74 qq[serialize with related_resultset "$key"]);
78 sub { $copy->discard_changes }, "Discard changes works: $name"
80 is($copy->id, $artist->id, "IDs still match ");
83 # Test resultsource with cached rows
85 $cd_rs = $cd_rs->search ({}, { cache => 1 });
87 $schema->storage->debug(1);
88 $schema->storage->debugcb(sub { $query_count++ } );
90 # this will hit the database once and prime the cache
91 my @cds = $cd_rs->all;
94 $copy = $store->($cd_rs);
98 "serialize cached resultset works: $name",
101 is ($copy->count, $cd_rs->count, 'Cached count identical');
102 } "serialize cached resultset lives: $name";
104 is ($query_count, 1, 'Only one db query fired');
106 $schema->storage->debug($orig_debug);
107 $schema->storage->debugcb(undef);