6 use lib 't/cdbi/testlib';
9 my $waves = Film->insert({
10 Title => "Breaking the Waves",
11 Director => 'Lars von Trier',
15 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 0;
18 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 1;
21 my $rating = $waves->{rating};
23 is $rating, "R", 'evaluation of column value is not deferred';
24 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
27 is $waves->{title}, $waves->Title, "columns can be accessed as hashes";
28 } qr{^Column 'title' of 'Film/$waves' was fetched as a hash at\b};
33 is $waves->{rating}, "G", "updating via the accessor updates the hash";
34 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
38 $waves->{rating} = "PG";
39 } qr{^Column 'rating' of 'Film/$waves' was stored as a hash at\b};
42 my @films = Film->search( Rating => "PG", Title => "Breaking the Waves" );
43 is @films, 1, "column updated as hash was saved";
48 } '', 'DBIC_CDBICOMPAT_HASH_WARN controls warnings';
55 no warnings 'redefine';
56 local *Film::rating = sub {
60 is $waves->{rating}, "R";
65 no warnings 'redefine';
67 local *Actor::accessor_name_for = sub {
68 my($class, $col) = @_;
69 return "movie" if lc $col eq "film";
74 Actor->has_a( film => "Film" );
76 my $actor = Actor->insert({
77 name => 'Emily Watson',
81 ok !eval { $actor->film };
82 is $actor->{film}->id, $waves->id,
83 'hash access still works despite lack of accessor';
87 # Emulate that Class::DBI inflates immediately
89 unless (eval { require MyFoo }) {
90 my ($err) = $@ =~ /([^\n]+)/;
94 my $foo = MyFoo->insert({
96 tdate => '1949-02-01',
100 isa_ok $foo->{tdate}, 'Date::Simple';
101 is $foo->{tdate}->year, 1949;