6 eval "use DBIx::Class::CDBICompat;";
7 plan skip_all => "Class::Trigger and DBIx::ContextualFetch required"
10 eval { require DateTime };
11 plan skip_all => "Need DateTime for inflation tests" if $@;
13 eval { require Clone };
14 plan skip_all => "Need Clone for CDBICompat inflation tests" if $@;
22 my $schema = DBICTest->init_schema();
24 DBICTest::Schema::CD->load_components(qw/CDBICompat::Relationships/);
26 DBICTest::Schema::CD->has_a( 'year', 'DateTime',
27 inflate => sub { DateTime->new( year => shift ) },
28 deflate => sub { shift->year }
30 Class::C3->reinitialize;
33 my $cd = $schema->resultset("CD")->find(3);
35 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
37 is( $cd->year->month, 1, 'inflated month ok' );
40 my $now = DateTime->now;
44 ($cd) = $schema->resultset("CD")->search( year => $now->year );
45 is( $cd->year->year, $now->year, 'deflate ok' );
47 # re-test using alternate deflate syntax
48 $schema->class("CD")->has_a( 'year', 'DateTime',
49 inflate => sub { DateTime->new( year => shift ) },
54 $cd = $schema->resultset("CD")->find(3);
56 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
58 is( $cd->year->month, 1, 'inflated month ok' );
65 ($cd) = $schema->resultset("CD")->search( year => $now->year );
66 is( $cd->year->year, $now->year, 'deflate ok' );