8 use Storable qw(dclone freeze thaw);
10 my $schema = DBICTest->init_schema();
13 dclone_method => sub { return $schema->dclone($_[0]) },
14 dclone_func => sub { return dclone($_[0]) },
15 "freeze/thaw_method" => sub {
16 my $ice = $schema->freeze($_[0]);
17 return $schema->thaw($ice);
19 "freeze/thaw_func" => sub {
24 plan tests => (11 * keys %stores);
26 for my $name (keys %stores) {
27 my $store = $stores{$name};
30 my $artist = $schema->resultset('Artist')->find(1);
32 # Test that the procedural versions will work if there's a registered
33 # schema as with CDBICompat objects and that the methods work
35 if( $name =~ /func/ ) {
36 $artist->result_source_instance->schema($schema);
37 DBICTest::CD->result_source_instance->schema($schema);
40 $artist->result_source_instance->schema(undef);
41 DBICTest::CD->result_source_instance->schema(undef);
44 lives_ok { $copy = $store->($artist) } "serialize row object lives: $name";
45 is_deeply($copy, $artist, "serialize row object works: $name");
47 my $cd_rs = $artist->search_related("cds");
49 # test that a result source can be serialized as well
51 $cd_rs->_resolved_attrs; # this builds up the {from} attr
54 $copy = $store->($cd_rs);
58 "serialize resultset works: $name",
60 } "serialize resultset lives: $name";
62 # Test that an object with a related_resultset can be serialized.
63 ok $artist->{related_resultsets}, 'has key: related_resultsets';
65 lives_ok { $copy = $store->($artist) } "serialize row object with related_resultset lives: $name";
66 for my $key (keys %$artist) {
67 next if $key eq 'related_resultsets';
68 next if $key eq '_inflated_column';
69 is_deeply($copy->{$key}, $artist->{$key},
70 qq[serialize with related_resultset "$key"]);
73 ok eval { $copy->discard_changes; 1 } or diag $@;
74 is($copy->id, $artist->id, "IDs still match ");