To: | bugs-Class-DBI [...] rt.cpan.org |
From: | Ask Bjørn Hansen <ask [...] develooper.com> |
Subject: | new accessor modifier doesn't default to also changing to mutator |
Date: | Sun, 27 Nov 2005 13:29:12 -0800 |
The documentation implies that if you change only the accessor the
mutator will default to the same name as the accessor.
In 3.0.7 (I think), this broke. Below is a test case that fails
with v3.0.12. The error I get is:
"... cannot alter the value of 'numexplodingsheep' on objects of
class 'Film' at t/15-accessor2.t line 38"
If I add
sub Film::mutator_name_for {
my ($class, $col) = @_;
return "sheep" if lc $col eq "numexplodingsheep";
return $col;
}
to the test case then it works, but in the past I didn't have to do
that (and again, the documentation implies that I shouldn't :-) )
Thank you! :-D
- ask
use strict;
use Test::More;
BEGIN {
eval "use DBD::SQLite";
plan $@ ? (skip_all => 'needs DBD::SQLite for testing') :
(tests => 6);
}
INIT {
local $SIG{__WARN__} =
sub { like $_[0], qr/clashes with built-in method/,
$_[0] };
use lib 't/testlib';
require Film;
}
sub Film::accessor_name_for {
my ($class, $col) = @_;
return "sheep" if lc $col eq "numexplodingsheep";
return $col;
}
my $data = {
Title => 'Bad Taste',
Director => 'Peter Jackson',
Rating => 'R',
};
my $bt;
eval {
my $data = $data;
$data->{sheep} = 1;
ok $bt = Film->insert($data), "Modified accessor - with
accessor";
isa_ok $bt, "Film";
};
is $@, '', "No errors";
eval {
ok $bt->sheep(2), 'Modified accessor, set';
ok $bt->update, 'Update';
};
is $@, '', "No errors";