6 eval "use DBIx::Class::CDBICompat;";
7 plan $@ ? (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@")
11 use lib 't/cdbi/testlib';
14 my $waves = Film->insert({
15 Title => "Breaking the Waves",
16 Director => 'Lars von Trier',
20 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 0;
23 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 1;
26 my $rating = $waves->{rating};
28 is $rating, "R", 'evaluation of column value is not deferred';
29 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at \Q$0};
32 is $waves->{title}, $waves->Title, "columns can be accessed as hashes";
33 } qr{^Column 'title' of 'Film/$waves' was fetched as a hash at\b};
38 is $waves->{rating}, "G", "updating via the accessor updates the hash";
39 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
43 $waves->{rating} = "PG";
44 } qr{^Column 'rating' of 'Film/$waves' was stored as a hash at\b};
47 my @films = Film->search( Rating => "PG", Title => "Breaking the Waves" );
48 is @films, 1, "column updated as hash was saved";
53 } '', 'DBIC_CDBICOMPAT_HASH_WARN controls warnings';
60 no warnings 'redefine';
61 local *Film::rating = sub {
65 is $waves->{rating}, "R";
70 no warnings 'redefine';
72 local *Actor::accessor_name_for = sub {
73 my($class, $col) = @_;
74 return "movie" if lc $col eq "film";
79 Actor->has_a( film => "Film" );
81 my $actor = Actor->insert({
82 name => 'Emily Watson',
86 ok !eval { $actor->film };
87 is $actor->{film}->id, $waves->id,
88 'hash access still works despite lack of accessor';
92 # Emulate that Class::DBI inflates immediately
94 skip "Need MySQL to run this test", 3 unless eval { require MyFoo };
96 my $foo = MyFoo->insert({
98 tdate => '1949-02-01',
100 isa_ok $foo, 'MyFoo';
102 isa_ok $foo->{tdate}, 'Date::Simple';
103 is $foo->{tdate}->year, 1949;