3 eval { require DateTime };
4 plan skip_all => "Need DateTime for inflation tests" if $@;
8 DBICTest::CD->load_components(qw/CDBICompat::HasA/);
10 DBICTest::CD->has_a( 'year', 'DateTime',
11 inflate => sub { DateTime->new( year => shift ) },
12 deflate => sub { shift->year }
16 my $cd = DBICTest::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) = DBICTest::CD->search( year => $now->year );
28 is( $cd->year->year, $now->year, 'deflate ok' );
30 # re-test using alternate deflate syntax
31 DBICTest::CD->has_a( 'year', 'DateTime',
32 inflate => sub { DateTime->new( year => shift ) },
37 $cd = DBICTest::CD->find(3);
39 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
41 is( $cd->year->month, 1, 'inflated month ok' );
48 ($cd) = DBICTest::CD->search( year => $now->year );
49 is( $cd->year->year, $now->year, 'deflate ok' );