From: Dan Kubb Date: Thu, 25 Aug 2005 07:17:08 +0000 (+0000) Subject: Added two new Fields attributes that specify the accessor and mutator name X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fce2732769f5849d97fb1038795e56c2383b4ec6;p=dbsrgits%2FDBIx-Class-Historic.git Added two new Fields attributes that specify the accessor and mutator name Added a BUILD method to Fields that sets the default accessor and mutator name, and label Integrated Fields with CDBI::Compat's AccessorMapping --- diff --git a/lib/DBIx/Class/CDBICompat/AccessorMapping.pm b/lib/DBIx/Class/CDBICompat/AccessorMapping.pm index 6d5e4b0..11fd13a 100644 --- a/lib/DBIx/Class/CDBICompat/AccessorMapping.pm +++ b/lib/DBIx/Class/CDBICompat/AccessorMapping.pm @@ -7,16 +7,10 @@ use NEXT; sub mk_group_accessors { my ($class, $group, @cols) = @_; - unless ($class->can('accessor_name') || $class->can('mutator_name')) { - return $class->NEXT::ACTUAL::mk_group_accessors($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 $field = $class->get_field($col); + my $ro_meth = $field->get_accessor_name; + my $wo_meth = $field->get_mutator_name; #warn "$col $ro_meth $wo_meth"; if ($ro_meth eq $wo_meth) { $class->NEXT::ACTUAL::mk_group_accessors($group => [ $ro_meth => $col ]); @@ -33,15 +27,13 @@ sub create { $attrs = { %$attrs }; my %att; foreach my $col (keys %{ $class->_columns }) { - if ($class->can('accessor_name')) { - my $acc = $class->accessor_name($col); -#warn "$col $acc"; - $att{$col} = delete $attrs->{$acc} if exists $attrs->{$acc}; - } - if ($class->can('mutator_name')) { - my $mut = $class->mutator_name($col); - $att{$col} = delete $attrs->{$mut} if exists $attrs->{$mut}; - } + my $field = $class->get_field($col); + + my $acc = $field->get_accessor_name; + $att{$col} = delete $attrs->{$acc} if exists $attrs->{$acc}; + + my $mut = $field->get_mutator_name; + $att{$col} = delete $attrs->{$mut} if exists $attrs->{$mut}; } return $class->NEXT::ACTUAL::create({ %$attrs, %att }, @rest); } diff --git a/lib/DBIx/Class/CDBICompat/TempColumns.pm b/lib/DBIx/Class/CDBICompat/TempColumns.pm index 64d6d20..557a26d 100644 --- a/lib/DBIx/Class/CDBICompat/TempColumns.pm +++ b/lib/DBIx/Class/CDBICompat/TempColumns.pm @@ -58,7 +58,7 @@ sub set_temp { } sub has_real_column { - return 1 if shift->_columns->{shift}; + return 1 if shift->_columns->{+shift}; } 1; diff --git a/lib/DBIx/Class/Field.pm b/lib/DBIx/Class/Field.pm index ac4ae49..fae55ae 100644 --- a/lib/DBIx/Class/Field.pm +++ b/lib/DBIx/Class/Field.pm @@ -17,7 +17,9 @@ use List::MoreUtils qw( any none ); use Class::Std; { my %name_of : ATTR( :init_arg :get ); - my %label_of : ATTR( :init_arg