1 package # hide from PAUSE Indexer
2 DBIx::Class::CDBICompat::AccessorMapping;
7 use base 'DBIx::Class';
9 use Scalar::Util 'blessed';
12 sub mk_group_accessors {
13 my ($class, $group, @cols) = @_;
15 foreach my $col (@cols) {
16 my($accessor, $col) = ref $col eq 'ARRAY' ? @$col : (undef, $col);
18 my($ro_meth, $wo_meth);
19 if (defined blessed $col and $col->isa('Class::DBI::Column')) {
20 $ro_meth = $col->accessor;
21 $wo_meth = $col->mutator;
23 elsif (defined $accessor and ($accessor ne $col)) {
24 $ro_meth = $wo_meth = $accessor;
27 $ro_meth = $class->accessor_name_for($col);
28 $wo_meth = $class->mutator_name_for($col);
31 # warn "class: $class / col: $col / ro: $ro_meth / wo: $wo_meth\n";
32 if ($ro_meth eq $wo_meth or # they're the same
33 $wo_meth eq $col) # or only the accessor is custom
35 $class->next::method($group => [ $ro_meth => $col ]);
38 $class->mk_group_ro_accessors($group => [ $ro_meth => $col ]);
39 $class->mk_group_wo_accessors($group => [ $wo_meth => $col ]);
45 sub accessor_name_for {
46 my ($class, $column) = @_;
47 if ($class->can('accessor_name')) {
48 return $class->accessor_name($column)
54 sub mutator_name_for {
55 my ($class, $column) = @_;
56 if ($class->can('mutator_name')) {
57 return $class->mutator_name($column)
65 my ($class, $attrs, @rest) = @_;
66 $class->throw_exception( "create needs a hashref" ) unless ref $attrs eq 'HASH';
67 foreach my $col ($class->columns) {
68 my $acc = $class->accessor_name_for($col);
69 $attrs->{$col} = delete $attrs->{$acc} if exists $attrs->{$acc};
71 my $mut = $class->mutator_name_for($col);
72 $attrs->{$col} = delete $attrs->{$mut} if exists $attrs->{$mut};
74 return $class->next::method($attrs, @rest);