1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat';
9 use lib 't/cdbi/testlib';
12 my $waves = Film->insert({
13 Title => "Breaking the Waves",
14 Director => 'Lars von Trier',
18 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 0;
21 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 1;
24 my $rating = $waves->{rating};
26 is $rating, "R", 'evaluation of column value is not deferred';
27 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
30 is $waves->{title}, $waves->Title, "columns can be accessed as hashes";
31 } qr{^Column 'title' of 'Film/$waves' was fetched as a hash at\b};
36 is $waves->{rating}, "G", "updating via the accessor updates the hash";
37 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
41 $waves->{rating} = "PG";
42 } qr{^Column 'rating' of 'Film/$waves' was stored as a hash at\b};
45 my @films = Film->search( Rating => "PG", Title => "Breaking the Waves" );
46 is @films, 1, "column updated as hash was saved";
51 } '', 'DBIC_CDBICOMPAT_HASH_WARN controls warnings';
58 no warnings 'redefine';
59 local *Film::rating = sub {
63 is $waves->{rating}, "R";
68 no warnings 'redefine';
70 local *Actor::accessor_name_for = sub {
71 my($class, $col) = @_;
72 return "movie" if lc $col eq "film";
77 Actor->has_a( film => "Film" );
79 my $actor = Actor->insert({
80 name => 'Emily Watson',
84 ok !eval { $actor->film };
85 is $actor->{film}->id, $waves->id,
86 'hash access still works despite lack of accessor';
90 # Emulate that Class::DBI inflates immediately
92 DBIx::Class::Optional::Dependencies->skip_without([qw( Date::Simple>=3.03 test_rdbms_mysql )]);
94 my $foo = MyFoo->insert({
96 tdate => '1949-02-01',
100 isa_ok $foo->{tdate}, 'Date::Simple';
101 is $foo->{tdate}->year, 1949;