1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat';
10 use lib 't/cdbi/testlib';
13 my $waves = Film->insert({
14 Title => "Breaking the Waves",
15 Director => 'Lars von Trier',
19 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 0;
22 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 1;
25 my $rating = $waves->{rating};
27 is $rating, "R", 'evaluation of column value is not deferred';
28 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
31 is $waves->{title}, $waves->Title, "columns can be accessed as hashes";
32 } qr{^Column 'title' of 'Film/$waves' was fetched as a hash at\b};
37 is $waves->{rating}, "G", "updating via the accessor updates the hash";
38 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
42 $waves->{rating} = "PG";
43 } qr{^Column 'rating' of 'Film/$waves' was stored as a hash at\b};
46 my @films = Film->search( Rating => "PG", Title => "Breaking the Waves" );
47 is @films, 1, "column updated as hash was saved";
52 } '', 'DBIC_CDBICOMPAT_HASH_WARN controls warnings';
59 no warnings 'redefine';
60 local *Film::rating = sub {
64 is $waves->{rating}, "R";
69 no warnings 'redefine';
71 local *Actor::accessor_name_for = sub {
72 my($class, $col) = @_;
73 return "movie" if lc $col eq "film";
78 Actor->has_a( film => "Film" );
80 my $actor = Actor->insert({
81 name => 'Emily Watson',
85 ok !eval { $actor->film };
86 is $actor->{film}->id, $waves->id,
87 'hash access still works despite lack of accessor';
91 # Emulate that Class::DBI inflates immediately
93 DBIx::Class::Optional::Dependencies->skip_without([qw( Date::Simple>=3.03 test_rdbms_mysql )]);
95 my $foo = MyFoo->insert({
97 tdate => '1949-02-01',
101 isa_ok $foo->{tdate}, 'Date::Simple';
102 is $foo->{tdate}->year, 1949;