4 eval { require DateTime };
5 plan skip_all => "Need DateTime for inflation tests" if $@;
9 DBICTest::Schema::CD->inflate_column( 'year',
10 { inflate => sub { DateTime->new( year => shift ) },
11 deflate => sub { shift->year } }
13 Class::C3->reinitialize;
16 my $cd = $schema->resultset("CD")->find(3);
18 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
20 is( $cd->year->month, 1, 'inflated month ok' );
23 my $now = DateTime->now;
27 ($cd) = $schema->resultset("CD")->search( year => $now->year );
28 is( $cd->year->year, $now->year, 'deflate ok' );
31 DBICTest::Schema::Serialized->inflate_column( 'serialized',
32 { inflate => sub { Load (shift) },
33 deflate => sub { die "Expecting a reference" unless (ref $_[0]); Dump (shift) } }
35 Class::C3->reinitialize;
47 serialized => [qw/a b 1 2/],
50 my $rs = $schema->resultset('Serialized');
52 my $entry = $rs->create($complex2);
54 ok($entry->update ($complex1), "update with hashref deflating ok");
56 ok($entry->update ($complex2), "update with arrayref deflating ok");