[Bast-commits] r4212 - in DBIx-Class/0.08/trunk:
lib/DBIx/Class/CDBICompat t/cdbi-t t/testlib
schwern at dev.catalyst.perl.org
schwern at dev.catalyst.perl.org
Sat Mar 15 07:13:01 GMT 2008
Author: schwern
Date: 2008-03-15 07:13:01 +0000 (Sat, 15 Mar 2008)
New Revision: 4212
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/CDBICompat/AccessorMapping.pm
DBIx-Class/0.08/trunk/t/cdbi-t/01-columns.t
DBIx-Class/0.08/trunk/t/testlib/Actor.pm
Log:
Simplify and speed up the accessor_name_for() code.
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/CDBICompat/AccessorMapping.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/CDBICompat/AccessorMapping.pm 2008-03-15 05:26:05 UTC (rev 4211)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/CDBICompat/AccessorMapping.pm 2008-03-15 07:13:01 UTC (rev 4212)
@@ -6,12 +6,10 @@
sub mk_group_accessors {
my ($class, $group, @cols) = @_;
- unless ($class->_can_accessor_name_for || $class->_can_mutator_name_for) {
- return $class->next::method($group => @cols);
- }
+
foreach my $col (@cols) {
- my $ro_meth = $class->_try_accessor_name_for($col);
- my $wo_meth = $class->_try_mutator_name_for($col);
+ my $ro_meth = $class->accessor_name_for($col);
+ my $wo_meth = $class->mutator_name_for($col);
# warn "class: $class / col: $col / ro: $ro_meth / wo: $wo_meth\n";
if ($ro_meth eq $wo_meth or # they're the same
@@ -25,33 +23,23 @@
}
}
-# CDBI 3.0.7 decided to change "accessor_name" and "mutator_name" to
-# "accessor_name_for" and "mutator_name_for". This is recent enough
-# that we should support both. CDBI does.
-sub _can_accessor_name_for {
- my $class = shift;
- return $class->can("accessor_name_for") || $class->can("accessor_name");
-}
-sub _can_mutator_name_for {
- my $class = shift;
- return $class->can("mutator_name_for") || $class->can("mutator_name");
-}
+sub accessor_name_for {
+ my ($class, $column) = @_;
+ if ($class->can('accessor_name')) {
+ return $class->accessor_name($column)
+ }
-sub _try_accessor_name_for {
- my($class, $column) = @_;
-
- my $method = $class->_can_accessor_name_for;
- return $column unless $method;
- return $class->$method($column);
+ return $column;
}
-sub _try_mutator_name_for {
- my($class, $column) = @_;
+sub mutator_name_for {
+ my ($class, $column) = @_;
+ if ($class->can('mutator_name')) {
+ return $class->mutator_name($column)
+ }
- my $method = $class->_can_mutator_name_for;
- return $column unless $method;
- return $class->$method($column);
+ return $column;
}
@@ -59,14 +47,11 @@
my ($class, $attrs, @rest) = @_;
$class->throw_exception( "create needs a hashref" ) unless ref $attrs eq 'HASH';
foreach my $col ($class->columns) {
- if ($class->_can_accessor_name_for) {
- my $acc = $class->_try_accessor_name_for($col);
+ my $acc = $class->accessor_name_for($col);
$attrs->{$col} = delete $attrs->{$acc} if exists $attrs->{$acc};
- }
- if ($class->_can_mutator_name_for) {
- my $mut = $class->_try_mutator_name_for($col);
+
+ my $mut = $class->mutator_name_for($col);
$attrs->{$col} = delete $attrs->{$mut} if exists $attrs->{$mut};
- }
}
return $class->next::method($attrs, @rest);
}
Modified: DBIx-Class/0.08/trunk/t/cdbi-t/01-columns.t
===================================================================
--- DBIx-Class/0.08/trunk/t/cdbi-t/01-columns.t 2008-03-15 05:26:05 UTC (rev 4211)
+++ DBIx-Class/0.08/trunk/t/cdbi-t/01-columns.t 2008-03-15 07:13:01 UTC (rev 4212)
@@ -22,13 +22,13 @@
State->columns(Other => qw/Capital Population/);
#State->has_many(cities => "City");
-sub accessor_name {
+sub accessor_name_for {
my ($class, $column) = @_;
my $return = $column eq "Rain" ? "Rainfall" : $column;
return $return;
}
-sub mutator_name {
+sub mutator_name_for {
my ($class, $column) = @_;
my $return = $column eq "Rain" ? "set_Rainfall" : "set_$column";
return $return;
Modified: DBIx-Class/0.08/trunk/t/testlib/Actor.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/testlib/Actor.pm 2008-03-15 05:26:05 UTC (rev 4211)
+++ DBIx-Class/0.08/trunk/t/testlib/Actor.pm 2008-03-15 07:13:01 UTC (rev 4212)
@@ -15,7 +15,7 @@
__PACKAGE__->columns(TEMP => qw/ nonpersistent /);
__PACKAGE__->add_constructor(salary_between => 'salary >= ? AND salary <= ?');
-sub mutator_name { "set_$_[1]" }
+sub mutator_name_for { "set_$_[1]" }
sub create_sql {
return qq{
More information about the Bast-commits
mailing list