8 my $schema = DBICTest->init_schema();
13 { module => 'YAML.pm',
14 inflater => sub { YAML::Load (shift) },
15 deflater => sub { die "Expecting a reference" unless (ref $_[0]); YAML::Dump (shift) },
17 { module => 'Storable.pm',
18 inflater => sub { Storable::thaw (shift) },
19 deflater => sub { die "Expecting a reference" unless (ref $_[0]); Storable::nfreeze (shift) },
25 foreach my $serializer (@serializers) {
26 eval { require $serializer->{module} };
28 $selected = $serializer;
33 plan (skip_all => "No suitable serializer found") unless $selected;
35 DBICTest::Schema::Serialized->inflate_column( 'serialized',
36 { inflate => $selected->{inflater},
37 deflate => $selected->{deflater},
40 Class::C3->reinitialize;
59 my $rs = $schema->resultset('Serialized');
62 #======= testing hashref serialization
64 my $object = $rs->create( {
67 ok($object->update( { serialized => $struct_hash } ), 'hashref deflation');
68 ok($inflated = $object->serialized, 'hashref inflation');
69 is_deeply($inflated, $struct_hash, 'inflated hash matches original');
71 $object = $rs->create( {
74 $object->set_inflated_column('serialized', $struct_hash);
75 is_deeply($object->serialized, $struct_hash, 'inflated hash matches original');
77 $object = $rs->new({});
78 $object->serialized ($struct_hash);
81 $rs->find ({id => $object->id})->serialized,
86 #====== testing arrayref serialization
88 ok($object->update( { serialized => $struct_array } ), 'arrayref deflation');
89 ok($inflated = $object->serialized, 'arrayref inflation');
90 is_deeply($inflated, $struct_array, 'inflated array matches original');
92 $object = $rs->new({});
93 $object->serialized ($struct_array);
96 $rs->find ({id => $object->id})->serialized,
101 #===== make sure make_column_dirty interacts reasonably with inflation
102 $object = $rs->first;
103 $object->update ({serialized => { x => 'y'}});
105 $object->serialized->{x} = 'z'; # change state without notifying $object
106 ok (!$object->get_dirty_columns, 'no dirty columns yet');
107 is_deeply ($object->serialized, { x => 'z' }, 'object data correct');
109 $object->make_column_dirty('serialized');
112 is_deeply ($rs->first->serialized, { x => 'z' }, 'changes made it to the db' );