8 eval "use DBIx::Class::CDBICompat;";
9 plan $@ ? (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@")
16 my $waves = Film->insert({
17 Title => "Breaking the Waves",
18 Director => 'Lars von Trier',
22 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 0;
25 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 1;
28 my $rating = $waves->{rating};
30 is $rating, "R", 'evaluation of column value is not deferred';
31 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at \Q$0};
34 is $waves->{title}, $waves->Title, "columns can be accessed as hashes";
35 } qr{^Column 'title' of 'Film/$waves' was fetched as a hash at\b};
40 is $waves->{rating}, "G", "updating via the accessor updates the hash";
41 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
45 $waves->{rating} = "PG";
46 } qr{^Column 'rating' of 'Film/$waves' was stored as a hash at\b};
49 my @films = Film->search( Rating => "PG", Title => "Breaking the Waves" );
50 is @films, 1, "column updated as hash was saved";
55 } '', 'DBIC_CDBICOMPAT_HASH_WARN controls warnings';
62 no warnings 'redefine';
63 local *Film::rating = sub {
67 is $waves->{rating}, "R";
72 no warnings 'redefine';
74 local *Actor::accessor_name_for = sub {
75 my($class, $col) = @_;
76 return "movie" if lc $col eq "film";
81 Actor->has_a( film => "Film" );
83 my $actor = Actor->insert({
84 name => 'Emily Watson',
88 ok !eval { $actor->film };
89 is $actor->{film}->id, $waves->id,
90 'hash access still works despite lack of accessor';
94 # Emulate that Class::DBI inflates immediately
96 skip "Need MySQL to run this test", 3 unless eval { require MyFoo };
98 my $foo = MyFoo->insert({
100 tdate => '1949-02-01',
102 isa_ok $foo, 'MyFoo';
104 isa_ok $foo->{tdate}, 'Date::Simple';
105 is $foo->{tdate}->year, 1949;