5 use lib 't/cdbi/testlib';
8 my $waves = Film->insert({
9 Title => "Breaking the Waves",
10 Director => 'Lars von Trier',
14 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 0;
17 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 1;
20 my $rating = $waves->{rating};
22 is $rating, "R", 'evaluation of column value is not deferred';
23 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
26 is $waves->{title}, $waves->Title, "columns can be accessed as hashes";
27 } qr{^Column 'title' of 'Film/$waves' was fetched as a hash at\b};
32 is $waves->{rating}, "G", "updating via the accessor updates the hash";
33 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
37 $waves->{rating} = "PG";
38 } qr{^Column 'rating' of 'Film/$waves' was stored as a hash at\b};
41 my @films = Film->search( Rating => "PG", Title => "Breaking the Waves" );
42 is @films, 1, "column updated as hash was saved";
47 } '', 'DBIC_CDBICOMPAT_HASH_WARN controls warnings';
54 no warnings 'redefine';
55 local *Film::rating = sub {
59 is $waves->{rating}, "R";
64 no warnings 'redefine';
66 local *Actor::accessor_name_for = sub {
67 my($class, $col) = @_;
68 return "movie" if lc $col eq "film";
73 Actor->has_a( film => "Film" );
75 my $actor = Actor->insert({
76 name => 'Emily Watson',
80 ok !eval { $actor->film };
81 is $actor->{film}->id, $waves->id,
82 'hash access still works despite lack of accessor';
86 # Emulate that Class::DBI inflates immediately
88 unless (eval { require MyFoo }) {
89 my ($err) = $@ =~ /([^\n]+)/;
93 my $foo = MyFoo->insert({
95 tdate => '1949-02-01',
99 isa_ok $foo->{tdate}, 'Date::Simple';
100 is $foo->{tdate}->year, 1949;