Class-DBI
view release on metacpan or search on metacpan
t/02-Film.t view on Meta::CPAN
# Don't re-load
$bt->add_trigger(
after_update => sub {
my ($self, %args) = @_;
my $discard_columns = $args{discard_columns};
@$discard_columns = qw/title/;
});
$bt->rating("19");
ok $bt->_attribute_exists('rating'), "changed column needs reloaded";
ok !$bt->_attribute_exists('title'), "but no longer have the title";
}
# Make sure that we can have other accessors. (Bugfix in 0.28)
if (0) {
Film->mk_accessors(qw/temp1 temp2/);
my $blrunner = Film->retrieve('Bladerunner');
$blrunner->temp1("Foo");
$blrunner->NumExplodingSheep(2);
eval { $blrunner->update };
ok(!$@, "Other accessors");
}
# overloading
{
is "$blrunner", "Bladerunner", "stringify";
ok(Film->columns(Stringify => 'rating'), "Can change stringify column");
is "$blrunner", "R", "And still stringifies correctly";
ok(
Film->columns(Stringify => qw/title rating/),
"Can have multiple stringify columns"
);
is "$blrunner", "Bladerunner/R", "And still stringifies correctly";
no warnings 'once';
local *Film::stringify_self = sub { join ":", $_[0]->title, $_[0]->rating };
is "$blrunner", "Bladerunner:R", "Provide stringify_self()";
}
{
{
ok my $byebye = DeletingFilm->insert({
Title => 'Goodbye Norma Jean',
Rating => 'PG',
}
),
"Add a deleting Film";
isa_ok $byebye, 'DeletingFilm';
isa_ok $byebye, 'Film';
ok(Film->retrieve('Goodbye Norma Jean'), "Fetch it back again");
}
my $film;
eval { $film = Film->retrieve('Goodbye Norma Jean') };
ok !$film, "It destroys itself";
}
SKIP: {
skip "Scalar::Util::weaken not available", 3
if !$Class::DBI::Weaken_Is_Available;
# my bad taste is your bad taste
my $btaste = Film->retrieve('Bad Taste');
my $btaste2 = Film->retrieve('Bad Taste');
is Scalar::Util::refaddr($btaste), Scalar::Util::refaddr($btaste2),
"Retrieving twice gives ref to same object";
$btaste2->remove_from_object_index;
my $btaste3 = Film->retrieve('Bad Taste');
isnt Scalar::Util::refaddr($btaste2), Scalar::Util::refaddr($btaste3),
"Removing from object_index and retrieving again gives new object";
$btaste3->clear_object_index;
my $btaste4 = Film->retrieve('Bad Taste');
isnt Scalar::Util::refaddr($btaste2), Scalar::Util::refaddr($btaste4),
"Clearing cache and retrieving again gives new object";
}
( run in 0.737 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )