3 eval { require DateTime };
4 plan skip_all => "Need DateTime for inflation tests" if $@;
12 use DBIx::Class::CDBICompat::HasA;
14 unshift(@DBICTest::ISA, 'DBIx::Class::CDBICompat::HasA');
16 DBICTest::CD->has_a( 'year', 'DateTime',
17 inflate => sub { DateTime->new( year => shift ) },
18 deflate => sub { shift->year }
22 my $cd = DBICTest::CD->retrieve(3);
24 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
26 is( $cd->year->month, 1, 'inflated month ok' );
29 my $now = DateTime->now;
33 ($cd) = DBICTest::CD->search( year => $now->year );
34 is( $cd->year->year, $now->year, 'deflate ok' );
36 # re-test using alternate deflate syntax
37 DBICTest::CD->has_a( 'year', 'DateTime',
38 inflate => sub { DateTime->new( year => shift ) },
43 $cd = DBICTest::CD->retrieve(3);
45 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
47 is( $cd->year->month, 1, 'inflated month ok' );
54 ($cd) = DBICTest::CD->search( year => $now->year );
55 is( $cd->year->year, $now->year, 'deflate ok' );