Merge 'trunk' into 'DBIx-Class-current'
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / CDBICompat / ColumnCase.pm
CommitLineData
c0e7b4e5 1package # hide from PAUSE
2 DBIx::Class::CDBICompat::ColumnCase;
ea2e61bf 3
4use strict;
5use warnings;
75a23b3e 6
7use base qw/DBIx::Class/;
ea2e61bf 8
9sub _register_column_group {
10 my ($class, $group, @cols) = @_;
147dd158 11 return $class->next::method($group => map lc, @cols);
ea2e61bf 12}
13
ec77fadc 14sub add_columns {
15 my ($class, @cols) = @_;
1f23a877 16 $class->mk_group_accessors(column => @cols);
8c49f629 17 $class->result_source_instance->add_columns(map lc, @cols);
ec77fadc 18}
19
12bbb339 20sub has_a {
21 my ($class, $col, @rest) = @_;
147dd158 22 $class->next::method(lc($col), @rest);
9f300b1b 23 $class->mk_group_accessors('inflated_column' => $col);
12bbb339 24 return 1;
25}
26
b8e1e21f 27sub has_many {
28 my ($class, $rel, $f_class, $f_key, @rest) = @_;
75d07914 29 return $class->next::method($rel, $f_class, ( ref($f_key) ?
30 $f_key :
be7fff92 31 lc($f_key) ), @rest);
b8e1e21f 32}
33
9f300b1b 34sub get_inflated_column {
12bbb339 35 my ($class, $get, @rest) = @_;
147dd158 36 return $class->next::method(lc($get), @rest);
12bbb339 37}
38
9f300b1b 39sub store_inflated_column {
12bbb339 40 my ($class, $set, @rest) = @_;
147dd158 41 return $class->next::method(lc($set), @rest);
12bbb339 42}
43
9f300b1b 44sub set_inflated_column {
12bbb339 45 my ($class, $set, @rest) = @_;
147dd158 46 return $class->next::method(lc($set), @rest);
ea2e61bf 47}
48
510ca912 49sub get_column {
ea2e61bf 50 my ($class, $get, @rest) = @_;
147dd158 51 return $class->next::method(lc($get), @rest);
ea2e61bf 52}
53
510ca912 54sub set_column {
ea2e61bf 55 my ($class, $set, @rest) = @_;
147dd158 56 return $class->next::method(lc($set), @rest);
510ca912 57}
58
59sub store_column {
60 my ($class, $set, @rest) = @_;
147dd158 61 return $class->next::method(lc($set), @rest);
ea2e61bf 62}
63
64sub find_column {
65 my ($class, $col) = @_;
147dd158 66 return $class->next::method(lc($col));
ea2e61bf 67}
68
9387c904 69# _build_query
70#
71# Build a query hash for find, et al. Overrides Retrieve::_build_query.
72
73sub _build_query {
74 my ($self, $query) = @_;
75
76 my %new_query;
77 $new_query{lc $_} = $query->{$_} for keys %$query;
78
79 return \%new_query;
80}
81
510ca912 82sub _mk_group_accessors {
83 my ($class, $type, $group, @fields) = @_;
b8e1e21f 84 #warn join(', ', map { ref $_ ? (@$_) : ($_) } @fields);
85 my @extra;
86 foreach (@fields) {
87 my ($acc, $field) = ref $_ ? @$_ : ($_, $_);
c687b87e 88 #warn "$acc ".lc($acc)." $field";
b8e1e21f 89 next if defined &{"${class}::${acc}"};
90 push(@extra, [ lc $acc => $field ]);
91 }
147dd158 92 return $class->next::method($type, $group,
b8e1e21f 93 @fields, @extra);
12bbb339 94}
95
12bbb339 96sub new {
97 my ($class, $attrs, @rest) = @_;
98 my %att;
99 $att{lc $_} = $attrs->{$_} for keys %$attrs;
147dd158 100 return $class->next::method(\%att, @rest);
ea2e61bf 101}
102
1031;