8 my $schema = DBICTest->init_schema();
10 eval { require DateTime };
11 plan skip_all => "Need DateTime for inflation tests" if $@;
15 DBICTest::Schema::CD->load_components(qw/CDBICompat::Relationships/);
17 DBICTest::Schema::CD->has_a( 'year', 'DateTime',
18 inflate => sub { DateTime->new( year => shift ) },
19 deflate => sub { shift->year }
21 Class::C3->reinitialize;
24 my $cd = $schema->resultset("CD")->find(3);
26 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
28 is( $cd->year->month, 1, 'inflated month ok' );
31 my $now = DateTime->now;
35 ($cd) = $schema->resultset("CD")->search( year => $now->year );
36 is( $cd->year->year, $now->year, 'deflate ok' );
38 # re-test using alternate deflate syntax
39 $schema->class("CD")->has_a( 'year', 'DateTime',
40 inflate => sub { DateTime->new( year => shift ) },
45 $cd = $schema->resultset("CD")->find(3);
47 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
49 is( $cd->year->month, 1, 'inflated month ok' );
56 ($cd) = $schema->resultset("CD")->search( year => $now->year );
57 is( $cd->year->year, $now->year, 'deflate ok' );