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 plan (skip_all => "No suitable serializer found") unless $selected;
33 DBICTest::Schema::Serialized->inflate_column( 'serialized',
34 { inflate => $selected->{inflater},
35 deflate => $selected->{deflater},
38 Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
57 my $rs = $schema->resultset('Serialized');
60 #======= testing hashref serialization
62 my $object = $rs->create( {
65 ok($object->update( { serialized => $struct_hash } ), 'hashref deflation');
66 ok($inflated = $object->serialized, 'hashref inflation');
67 is_deeply($inflated, $struct_hash, 'inflated hash matches original');
69 $object = $rs->create( {
72 $object->set_inflated_column('serialized', $struct_hash);
73 is_deeply($object->serialized, $struct_hash, 'inflated hash matches original');
75 $object = $rs->new({});
76 $object->serialized ($struct_hash);
79 $rs->find ({id => $object->id})->serialized,
84 #====== testing arrayref serialization
86 ok($object->update( { serialized => $struct_array } ), 'arrayref deflation');
87 ok($inflated = $object->serialized, 'arrayref inflation');
88 is_deeply($inflated, $struct_array, 'inflated array matches original');
90 $object = $rs->new({});
91 $object->serialized ($struct_array);
94 $rs->find ({id => $object->id})->serialized,
99 #===== make sure make_column_dirty interacts reasonably with inflation
100 $object = $rs->first;
101 $object->update ({serialized => { x => 'y'}});
103 $object->serialized->{x} = 'z'; # change state without notifying $object
104 ok (!$object->get_dirty_columns, 'no dirty columns yet');
105 is_deeply ($object->serialized, { x => 'z' }, 'object data correct');
107 $object->make_column_dirty('serialized');
110 is_deeply ($rs->first->serialized, { x => 'z' }, 'changes made it to the db' );