X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FAccessorMapping.pm;h=b7945b093ab2156727e9b691e6274b73d84a7352;hb=7fca91be5671c61be5c766bd93df741bc00d9c15;hp=a8f03e6c2345acb5b9b0ad6a4515bad9af3cf8c5;hpb=05ccf06442bb026dda959e83ef451f9f40105d2b;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/CDBICompat/AccessorMapping.pm b/lib/DBIx/Class/CDBICompat/AccessorMapping.pm index a8f03e6..b7945b0 100644 --- a/lib/DBIx/Class/CDBICompat/AccessorMapping.pm +++ b/lib/DBIx/Class/CDBICompat/AccessorMapping.pm @@ -1,26 +1,35 @@ package # hide from PAUSE Indexer - DBIx::Class::CDBICompat::AccessorMapping; + DBIx::Class::CDBICompat::AccessorMapping; use strict; use warnings; sub mk_group_accessors { - my ($class, $group, @cols) = @_; - - foreach my $col (@cols) { - 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 - $wo_meth eq $col) # or only the accessor is custom - { - $class->next::method($group => [ $ro_meth => $col ]); - } else { - $class->mk_group_ro_accessors($group => [ $ro_meth => $col ]); - $class->mk_group_wo_accessors($group => [ $wo_meth => $col ]); + my ($class, $group, @cols) = @_; + + foreach my $col (@cols) { + my($accessor, $col) = ref $col ? @$col : (undef, $col); + + my($ro_meth, $wo_meth); + if( defined $accessor and ($accessor ne $col)) { + $ro_meth = $wo_meth = $accessor; + } + else { + $ro_meth = $class->accessor_name_for($col); + $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 + $wo_meth eq $col) # or only the accessor is custom + { + $class->next::method($group => [ $ro_meth => $col ]); + } + else { + $class->mk_group_ro_accessors($group => [ $ro_meth => $col ]); + $class->mk_group_wo_accessors($group => [ $wo_meth => $col ]); + } } - } } @@ -44,16 +53,16 @@ sub mutator_name_for { sub new { - my ($class, $attrs, @rest) = @_; - $class->throw_exception( "create needs a hashref" ) unless ref $attrs eq 'HASH'; - foreach my $col ($class->columns) { - my $acc = $class->accessor_name_for($col); - $attrs->{$col} = delete $attrs->{$acc} if exists $attrs->{$acc}; - - my $mut = $class->mutator_name_for($col); - $attrs->{$col} = delete $attrs->{$mut} if exists $attrs->{$mut}; - } - return $class->next::method($attrs, @rest); + my ($class, $attrs, @rest) = @_; + $class->throw_exception( "create needs a hashref" ) unless ref $attrs eq 'HASH'; + foreach my $col ($class->columns) { + my $acc = $class->accessor_name_for($col); + $attrs->{$col} = delete $attrs->{$acc} if exists $attrs->{$acc}; + + my $mut = $class->mutator_name_for($col); + $attrs->{$col} = delete $attrs->{$mut} if exists $attrs->{$mut}; + } + return $class->next::method($attrs, @rest); } 1;