With the addition of Class::C3 0.07 and a few tweaks, C3 branch works!
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / AccessorMapping.pm
CommitLineData
ea2e61bf 1package DBIx::Class::CDBICompat::AccessorMapping;
2
3use strict;
4use warnings;
5
b8e1e21f 6sub mk_group_accessors {
7 my ($class, $group, @cols) = @_;
ea2e61bf 8 unless ($class->can('accessor_name') || $class->can('mutator_name')) {
147dd158 9 return $class->next::method($group => @cols);
ea2e61bf 10 }
11 foreach my $col (@cols) {
12 my $ro_meth = ($class->can('accessor_name')
13 ? $class->accessor_name($col)
14 : $col);
15 my $wo_meth = ($class->can('mutator_name')
16 ? $class->mutator_name($col)
17 : $col);
c687b87e 18 #warn "$col $ro_meth $wo_meth";
ea2e61bf 19 if ($ro_meth eq $wo_meth) {
147dd158 20 $class->next::method($group => [ $ro_meth => $col ]);
ea2e61bf 21 } else {
b8e1e21f 22 $class->mk_group_ro_accessors($group => [ $ro_meth => $col ]);
23 $class->mk_group_wo_accessors($group => [ $wo_meth => $col ]);
ea2e61bf 24 }
25 }
26}
27
75a23b3e 28sub new {
9bc6db13 29 my ($class, $attrs, @rest) = @_;
78bab9ca 30 $class->throw( "create needs a hashref" ) unless ref $attrs eq 'HASH';
103647d5 31 foreach my $col ($class->columns) {
9bc6db13 32 if ($class->can('accessor_name')) {
33 my $acc = $class->accessor_name($col);
75a23b3e 34 $attrs->{$col} = delete $attrs->{$acc} if exists $attrs->{$acc};
9bc6db13 35 }
36 if ($class->can('mutator_name')) {
37 my $mut = $class->mutator_name($col);
75a23b3e 38 $attrs->{$col} = delete $attrs->{$mut} if exists $attrs->{$mut};
9bc6db13 39 }
40 }
75a23b3e 41 return $class->next::method($attrs, @rest);
9bc6db13 42}
43
ea2e61bf 441;