Commit | Line | Data |
c0e7b4e5 |
1 | package # hide from PAUSE |
2 | DBIx::Class::CDBICompat::ColumnCase; |
ea2e61bf |
3 | |
4 | use strict; |
5 | use warnings; |
75a23b3e |
6 | |
7 | use base qw/DBIx::Class/; |
ea2e61bf |
8 | |
9 | sub _register_column_group { |
10 | my ($class, $group, @cols) = @_; |
147dd158 |
11 | return $class->next::method($group => map lc, @cols); |
ea2e61bf |
12 | } |
13 | |
ec77fadc |
14 | sub 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 |
20 | sub 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 |
27 | sub has_many { |
28 | my ($class, $rel, $f_class, $f_key, @rest) = @_; |
147dd158 |
29 | return $class->next::method($rel, $f_class, ( ref($f_key) ? |
be7fff92 |
30 | $f_key : |
31 | lc($f_key) ), @rest); |
b8e1e21f |
32 | } |
33 | |
9f300b1b |
34 | sub get_inflated_column { |
12bbb339 |
35 | my ($class, $get, @rest) = @_; |
147dd158 |
36 | return $class->next::method(lc($get), @rest); |
12bbb339 |
37 | } |
38 | |
9f300b1b |
39 | sub store_inflated_column { |
12bbb339 |
40 | my ($class, $set, @rest) = @_; |
147dd158 |
41 | return $class->next::method(lc($set), @rest); |
12bbb339 |
42 | } |
43 | |
9f300b1b |
44 | sub set_inflated_column { |
12bbb339 |
45 | my ($class, $set, @rest) = @_; |
147dd158 |
46 | return $class->next::method(lc($set), @rest); |
ea2e61bf |
47 | } |
48 | |
510ca912 |
49 | sub get_column { |
ea2e61bf |
50 | my ($class, $get, @rest) = @_; |
147dd158 |
51 | return $class->next::method(lc($get), @rest); |
ea2e61bf |
52 | } |
53 | |
510ca912 |
54 | sub set_column { |
ea2e61bf |
55 | my ($class, $set, @rest) = @_; |
147dd158 |
56 | return $class->next::method(lc($set), @rest); |
510ca912 |
57 | } |
58 | |
59 | sub store_column { |
60 | my ($class, $set, @rest) = @_; |
147dd158 |
61 | return $class->next::method(lc($set), @rest); |
ea2e61bf |
62 | } |
63 | |
64 | sub find_column { |
65 | my ($class, $col) = @_; |
147dd158 |
66 | return $class->next::method(lc($col)); |
ea2e61bf |
67 | } |
68 | |
510ca912 |
69 | sub _mk_group_accessors { |
70 | my ($class, $type, $group, @fields) = @_; |
b8e1e21f |
71 | #warn join(', ', map { ref $_ ? (@$_) : ($_) } @fields); |
72 | my @extra; |
73 | foreach (@fields) { |
74 | my ($acc, $field) = ref $_ ? @$_ : ($_, $_); |
c687b87e |
75 | #warn "$acc ".lc($acc)." $field"; |
b8e1e21f |
76 | next if defined &{"${class}::${acc}"}; |
77 | push(@extra, [ lc $acc => $field ]); |
78 | } |
147dd158 |
79 | return $class->next::method($type, $group, |
b8e1e21f |
80 | @fields, @extra); |
12bbb339 |
81 | } |
82 | |
12bbb339 |
83 | sub new { |
84 | my ($class, $attrs, @rest) = @_; |
85 | my %att; |
86 | $att{lc $_} = $attrs->{$_} for keys %$attrs; |
147dd158 |
87 | return $class->next::method(\%att, @rest); |
ea2e61bf |
88 | } |
89 | |
90 | 1; |