Subject: | [PATCH] CDBICompat does not support accessor_name_for/mutator_name_for |
CDBI 3.0.7 decided to change "accessor_name" and "mutator_name" to
"accessor_name_for" and "mutator_name_for". CDBI continues to support
the old names. CDBICompat only supports the old name.
This patch makes CDBICompat support both.
Subject: | accessor_name_for.patch |
----------------------------------------------------------------------
r27708: schwern | 2007-03-16 19:24:49 -0700
CDBI 3.0.7 decided to change "accessor_name" and "mutator_name" to "accessor_name_for" and "mutator_name_for". CDBI continues to support the old names. CDBICompat only supports the old name.
----------------------------------------------------------------------
=== local/DBIx-Class/t/cdbi-t/15-accessor.t
==================================================================
--- local/DBIx-Class/t/cdbi-t/15-accessor.t (revision 27707)
+++ local/DBIx-Class/t/cdbi-t/15-accessor.t (revision 27708)
@@ -4,6 +4,7 @@
BEGIN {
eval "use DBIx::Class::CDBICompat;";
if ($@) {
+ diag $@;
plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
next;
}
@@ -33,7 +34,7 @@
return $col;
}
-sub Actor::accessor_name {
+sub Actor::accessor_name_for {
my ($class, $col) = @_;
return "movie" if lc $col eq "film";
return $col;
=== local/DBIx-Class/lib/DBIx/Class/CDBICompat/AccessorMapping.pm
==================================================================
--- local/DBIx-Class/lib/DBIx/Class/CDBICompat/AccessorMapping.pm (revision 27707)
+++ local/DBIx-Class/lib/DBIx/Class/CDBICompat/AccessorMapping.pm (revision 27708)
@@ -6,16 +6,13 @@
sub mk_group_accessors {
my ($class, $group, @cols) = @_;
- unless ($class->can('accessor_name') || $class->can('mutator_name')) {
+ 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->can('accessor_name')
- ? $class->accessor_name($col)
- : $col);
- my $wo_meth = ($class->can('mutator_name')
- ? $class->mutator_name($col)
- : $col);
+ my $ro_meth = $class->_try_accessor_name_for($col);
+ my $wo_meth = $class->_try_mutator_name_for($col);
+
#warn "$col $ro_meth $wo_meth";
if ($ro_meth eq $wo_meth) {
$class->next::method($group => [ $ro_meth => $col ]);
@@ -26,16 +23,46 @@
}
}
+# 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") || $class->can("accessor_name_for");
+}
+
+sub _can_mutator_name_for {
+ my $class = shift;
+ return $class->can("mutator_name") || $class->can("mutator_name_for");
+}
+
+sub _try_accessor_name_for {
+ my($class, $column) = @_;
+
+ my $method = $class->_can_accessor_name_for;
+ return $column unless $method;
+ return $class->$method($column);
+}
+
+sub _try_mutator_name_for {
+ my($class, $column) = @_;
+
+ my $method = $class->_can_mutator_name_for;
+ return $column unless $method;
+ return $class->$method($column);
+}
+
+
sub new {
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')) {
- my $acc = $class->accessor_name($col);
+ if ($class->_can_accessor_name_for) {
+ my $acc = $class->_try_accessor_name_for($col);
$attrs->{$col} = delete $attrs->{$acc} if exists $attrs->{$acc};
}
- if ($class->can('mutator_name')) {
- my $mut = $class->mutator_name($col);
+ if ($class->_can_mutator_name_for) {
+ my $mut = $class->_try_mutator_name_for($col);
$attrs->{$col} = delete $attrs->{$mut} if exists $attrs->{$mut};
}
}