3 eval { require DateTime };
4 plan skip_all => "Need DateTime for inflation tests" if $@;
12 DBICTest::CD->load_components(qw/CDBICompat::HasA/);
14 DBICTest::CD->has_a( 'year', 'DateTime',
15 inflate => sub { DateTime->new( year => shift ) },
16 deflate => sub { shift->year }
20 my $cd = DBICTest::CD->find(3);
22 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
24 is( $cd->year->month, 1, 'inflated month ok' );
27 my $now = DateTime->now;
31 ($cd) = DBICTest::CD->search( year => $now->year );
32 is( $cd->year->year, $now->year, 'deflate ok' );
34 # re-test using alternate deflate syntax
35 DBICTest::CD->has_a( 'year', 'DateTime',
36 inflate => sub { DateTime->new( year => shift ) },
41 $cd = DBICTest::CD->find(3);
43 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
45 is( $cd->year->month, 1, 'inflated month ok' );
52 ($cd) = DBICTest::CD->search( year => $now->year );
53 is( $cd->year->year, $now->year, 'deflate ok' );