Subject: | redundant calls to make_accessor() |
Class::DBI 0.96
perl 5.8.0
Linux 2.4.20
When creating the column accessors in _mk_column_accessors,
if the set and get methods have the same name (i.e., mutator_name is not
overridden), make_accessor() is called twice for the same accessor.
That's cause %method always has two keys, 'ro' and 'wo,' that we iterate
over even when $both is true.
The patch modifies %method in the case where the names match,
causing make_accessor() to only be called once.
--- lib/Class/DBI.pm.orig 2004-06-24 10:52:02.000000000 -0700
+++ lib/Class/DBI.pm 2004-06-24 10:53:02.000000000 -0700
@@ -383,13 +383,13 @@
my $class = shift;
foreach my $obj ($class->_find_columns(@_)) {
my %method = (
- ro => $obj->accessor($class->accessor_name($obj->name)),
- wo => $obj->mutator($class->mutator_name($obj->name)),
+ _ro => $obj->accessor($class->accessor_name($obj->name)),
+ _wo => $obj->mutator($class->mutator_name($obj->name)),
);
- my $both = ($method{ro} eq $method{wo});
+ %method = ('' => $method{_ro}) if $method{_ro} eq $method{_wo};
foreach my $type (keys %method) {
my $name = $method{$type};
- my $acc_type = $both ? "make_accessor" : "make_${type}_accessor";
+ my $acc_type = "make${type}_accessor";
my $accessor = $class->$acc_type($obj->name_lc);
$class->_make_method($_, $accessor) for ($name, "_${name}_accessor");
}