3 eval { require DateTime };
4 plan skip_all => "Need DateTime for inflation tests" if $@;
8 DBICTest::Schema::CD->load_components(qw/CDBICompat::HasA/);
10 DBICTest::Schema::CD->has_a( 'year', 'DateTime',
11 inflate => sub { DateTime->new( year => shift ) },
12 deflate => sub { shift->year }
14 Class::C3->reinitialize;
17 my $cd = DBICTest->class("CD")->find(3);
19 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
21 is( $cd->year->month, 1, 'inflated month ok' );
24 my $now = DateTime->now;
28 ($cd) = DBICTest->class("CD")->search( year => $now->year );
29 is( $cd->year->year, $now->year, 'deflate ok' );
31 # re-test using alternate deflate syntax
32 DBICTest->class("CD")->has_a( 'year', 'DateTime',
33 inflate => sub { DateTime->new( year => shift ) },
38 $cd = DBICTest->class("CD")->find(3);
40 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
42 is( $cd->year->month, 1, 'inflated month ok' );
49 ($cd) = DBICTest->class("CD")->search( year => $now->year );
50 is( $cd->year->year, $now->year, 'deflate ok' );