1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
10 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 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->search({}, { rows => 1 })->next;
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' );