5 use lib 't/cdbi/testlib';
8 sub create_trigger2 { ::ok(1, "Running create trigger 2"); }
9 sub delete_trigger { ::ok(1, "Deleting " . shift->Title) }
12 $_[0]->_attribute_set(numexplodingsheep => 1);
13 ::ok(1, "Running pre-update trigger");
15 sub pst_up_trigger { ::ok(1, "Running post-update trigger"); }
17 sub default_rating { $_[0]->Rating(15); }
19 Film->add_trigger(before_create => \&default_rating);
20 Film->add_trigger(after_create => \&create_trigger2);
21 Film->add_trigger(after_delete => \&delete_trigger);
22 Film->add_trigger(before_update => \&pre_up_trigger);
23 Film->add_trigger(after_update => \&pst_up_trigger);
26 my $ver = Film->create({
27 title => 'La Double Vie De Veronique',
28 director => 'Kryzstof Kieslowski',
31 numexplodingsheep => 0,
37 is $ver->Rating, 15, "Default rating";
38 is $ver->NumExplodingSheep, 0, "Original sheep count";
39 ok $ver->Rating('12') && $ver->update, "Change the rating";
40 is $ver->NumExplodingSheep, 1, "Updated object's sheep count";
42 $ver->db_Main->selectall_arrayref(
43 'SELECT numexplodingsheep FROM '
46 . $ver->primary_column . ' = '
47 . $ver->db_Main->quote($ver->id))
48 )->[0]->[0], 1, "Updated database's sheep count";
49 ok $ver->delete, "Delete";
52 Film->add_trigger(before_create => sub {
54 ok !$self->_attribute_exists('title'), "PK doesn't auto-vivify";
56 Film->create({director => "Me"});