1 package # hide from PAUSE Indexer
2 DBIx::Class::CDBICompat::AccessorMapping;
7 sub mk_group_accessors {
8 my ($class, $group, @cols) = @_;
10 foreach my $col (@cols) {
11 my($accessor, $col) = ref $col ? @$col : (undef, $col);
13 my($ro_meth, $wo_meth);
14 if( defined $accessor and ($accessor ne $col)) {
15 $ro_meth = $wo_meth = $accessor;
18 $ro_meth = $class->accessor_name_for($col);
19 $wo_meth = $class->mutator_name_for($col);
22 # warn "class: $class / col: $col / ro: $ro_meth / wo: $wo_meth\n";
23 if ($ro_meth eq $wo_meth or # they're the same
24 $wo_meth eq $col) # or only the accessor is custom
26 $class->next::method($group => [ $ro_meth => $col ]);
29 $class->mk_group_ro_accessors($group => [ $ro_meth => $col ]);
30 $class->mk_group_wo_accessors($group => [ $wo_meth => $col ]);
36 sub accessor_name_for {
37 my ($class, $column) = @_;
38 if ($class->can('accessor_name')) {
39 return $class->accessor_name($column)
45 sub mutator_name_for {
46 my ($class, $column) = @_;
47 if ($class->can('mutator_name')) {
48 return $class->mutator_name($column)
56 my ($class, $attrs, @rest) = @_;
57 $class->throw_exception( "create needs a hashref" ) unless ref $attrs eq 'HASH';
58 foreach my $col ($class->columns) {
59 my $acc = $class->accessor_name_for($col);
60 $attrs->{$col} = delete $attrs->{$acc} if exists $attrs->{$acc};
62 my $mut = $class->mutator_name_for($col);
63 $attrs->{$col} = delete $attrs->{$mut} if exists $attrs->{$mut};
65 return $class->next::method($attrs, @rest);