8 my $schema = DBICTest->init_schema();
11 { module => 'YAML.pm',
12 inflater => sub { YAML::Load (shift) },
13 deflater => sub { die "Expecting a reference" unless (ref $_[0]); YAML::Dump (shift) },
15 { module => 'Storable.pm',
16 inflater => sub { Storable::thaw (shift) },
17 deflater => sub { die "Expecting a reference" unless (ref $_[0]); Storable::nfreeze (shift) },
23 foreach my $serializer (@serializers) {
24 eval { require $serializer->{module} };
26 $selected = $serializer;
31 DBICTest::Schema::Serialized->inflate_column( 'serialized',
32 { inflate => $selected->{inflater},
33 deflate => $selected->{deflater},
36 Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
55 my $rs = $schema->resultset('Serialized');
58 #======= testing hashref serialization
60 my $object = $rs->create( {
63 ok($object->update( { serialized => $struct_hash } ), 'hashref deflation');
64 ok($inflated = $object->serialized, 'hashref inflation');
65 is_deeply($inflated, $struct_hash, 'inflated hash matches original');
67 $object = $rs->create( {
70 $object->set_inflated_column('serialized', $struct_hash);
71 is_deeply($object->serialized, $struct_hash, 'inflated hash matches original');
73 $object = $rs->new({});
74 $object->serialized ($struct_hash);
77 $rs->find ({id => $object->id})->serialized,
82 #====== testing arrayref serialization
84 ok($object->update( { serialized => $struct_array } ), 'arrayref deflation');
85 ok($inflated = $object->serialized, 'arrayref inflation');
86 is_deeply($inflated, $struct_array, 'inflated array matches original');
88 $object = $rs->new({});
89 $object->serialized ($struct_array);
92 $rs->find ({id => $object->id})->serialized,
97 #===== make sure make_column_dirty interacts reasonably with inflation
98 $object = $rs->search({}, { rows => 1 })->next;
99 $object->update ({serialized => { x => 'y'}});
101 $object->serialized->{x} = 'z'; # change state without notifying $object
102 ok (!$object->get_dirty_columns, 'no dirty columns yet');
103 is_deeply ($object->serialized, { x => 'z' }, 'object data correct');
105 $object->make_column_dirty('serialized');
108 is_deeply ($rs->first->serialized, { x => 'z' }, 'changes made it to the db' );