Also takes an options hashref of C<< column_name => value> pairs >> to update
first. But be aware that this hashref might be edited in place, so dont rely on
-it being the same after a call to C<update>.
+it being the same after a call to C<update>. If you need to preserve the hashref,
+it is sufficient to pass a shallow copy to C<update>, e.g. ( { %{ $href } } )
=cut
);
Class::C3->reinitialize;
-my $complex1 = {
- id => 1,
- serialized => {
- a => 1,
- b => [
- { c => 2 },
- ],
- d => 3,
- },
+my $struct_hash = {
+ a => 1,
+ b => [
+ { c => 2 },
+ ],
+ d => 3,
};
-my $complex2 = {
- id => 1,
- serialized => [
- 'a',
- { b => 1, c => 2},
- 'd',
- ],
-};
+my $struct_array = [
+ 'a',
+ {
+ b => 1,
+ c => 2
+ },
+ 'd',
+];
my $rs = $schema->resultset('Serialized');
-my $entry = $rs->create({ id => 1, serialized => ''});
-
my $inflated;
-ok($entry->update ({ %{$complex1} }), 'hashref deflation ok');
-ok($inflated = $entry->serialized, 'hashref inflation ok');
-is_deeply($inflated, $complex1->{serialized}, 'inflated hash matches original');
-
-my $entry2 = $rs->create({ id => 2, serialized => ''});
+#======= testing hashref serialization
-eval { $entry2->set_inflated_column('serialized', $complex1->{serialized}) };
+my $object = $rs->create( {
+ id => 1,
+ serialized => '',
+} );
+ok($object->update( { serialized => $struct_hash } ), 'hashref deflation');
+ok($inflated = $object->serialized, 'hashref inflation');
+is_deeply($inflated, $struct_hash, 'inflated hash matches original');
+
+$object = $rs->create( {
+ id => 2,
+ serialized => '',
+} );
+eval { $object->set_inflated_column('serialized', $struct_hash) };
ok(!$@, 'set_inflated_column to a hashref');
-$entry2->update;
-is_deeply($entry2->serialized, $complex1->{serialized}, 'inflated hash matches original');
+is_deeply($object->serialized, $struct_hash, 'inflated hash matches original');
+
-ok($entry->update ({ %{$complex2} }), 'arrayref deflation ok');
-ok($inflated = $entry->serialized, 'arrayref inflation ok');
-is_deeply($inflated, $complex2->{serialized}, 'inflated array matches original');
+#====== testing arrayref serialization
+ok($object->update( { serialized => $struct_array } ), 'arrayref deflation');
+ok($inflated = $object->serialized, 'arrayref inflation');
+is_deeply($inflated, $struct_array, 'inflated array matches original');