discard_changes is also "refresh from storage"
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / CDBICompat / AccessorMapping.pm
CommitLineData
c0e7b4e5 1package # hide from PAUSE Indexer
2 DBIx::Class::CDBICompat::AccessorMapping;
ea2e61bf 3
4use strict;
5use warnings;
6
b8e1e21f 7sub mk_group_accessors {
8 my ($class, $group, @cols) = @_;
ea2e61bf 9 unless ($class->can('accessor_name') || $class->can('mutator_name')) {
147dd158 10 return $class->next::method($group => @cols);
ea2e61bf 11 }
12 foreach my $col (@cols) {
13 my $ro_meth = ($class->can('accessor_name')
14 ? $class->accessor_name($col)
15 : $col);
16 my $wo_meth = ($class->can('mutator_name')
17 ? $class->mutator_name($col)
18 : $col);
c687b87e 19 #warn "$col $ro_meth $wo_meth";
ea2e61bf 20 if ($ro_meth eq $wo_meth) {
147dd158 21 $class->next::method($group => [ $ro_meth => $col ]);
ea2e61bf 22 } else {
b8e1e21f 23 $class->mk_group_ro_accessors($group => [ $ro_meth => $col ]);
24 $class->mk_group_wo_accessors($group => [ $wo_meth => $col ]);
ea2e61bf 25 }
26 }
27}
28
75a23b3e 29sub new {
9bc6db13 30 my ($class, $attrs, @rest) = @_;
701da8c4 31 $class->throw_exception( "create needs a hashref" ) unless ref $attrs eq 'HASH';
103647d5 32 foreach my $col ($class->columns) {
9bc6db13 33 if ($class->can('accessor_name')) {
34 my $acc = $class->accessor_name($col);
75a23b3e 35 $attrs->{$col} = delete $attrs->{$acc} if exists $attrs->{$acc};
9bc6db13 36 }
37 if ($class->can('mutator_name')) {
38 my $mut = $class->mutator_name($col);
75a23b3e 39 $attrs->{$col} = delete $attrs->{$mut} if exists $attrs->{$mut};
9bc6db13 40 }
41 }
75a23b3e 42 return $class->next::method($attrs, @rest);
9bc6db13 43}
44
ea2e61bf 451;