Commit | Line | Data |
c0e7b4e5 |
1 | package # hide from PAUSE |
2 | DBIx::Class::CDBICompat::Retrieve; |
656796f2 |
3 | |
4 | use strict; |
5 | use warnings FATAL => 'all'; |
6 | |
716b3d29 |
7 | |
9387c904 |
8 | sub retrieve { |
9 | my $self = shift; |
10 | die "No args to retrieve" unless @_ > 0; |
11 | |
12 | my @cols = $self->primary_columns; |
13 | |
14 | my $query; |
15 | if (ref $_[0] eq 'HASH') { |
16 | $query = { %{$_[0]} }; |
17 | } |
18 | elsif (@_ == @cols) { |
19 | $query = {}; |
20 | @{$query}{@cols} = @_; |
21 | } |
22 | else { |
23 | $query = {@_}; |
24 | } |
25 | |
26 | $query = $self->_build_query($query); |
27 | $self->find($query); |
28 | } |
29 | |
30 | sub find_or_create { |
31 | my $self = shift; |
32 | my $query = ref $_[0] eq 'HASH' ? shift : {@_}; |
33 | |
34 | $query = $self->_build_query($query); |
35 | $self->next::method($query); |
36 | } |
37 | |
38 | # _build_query |
39 | # |
40 | # Build a query hash. Defaults to a no-op; ColumnCase overrides. |
41 | |
42 | sub _build_query { |
43 | my ($self, $query) = @_; |
44 | |
45 | return $query; |
716b3d29 |
46 | } |
6009260a |
47 | |
48 | sub retrieve_from_sql { |
49 | my ($class, $cond, @rest) = @_; |
50 | $cond =~ s/^\s*WHERE//i; |
51 | $class->search_literal($cond, @rest); |
52 | } |
656796f2 |
53 | |
716b3d29 |
54 | sub retrieve_all { shift->search } |
3125eb1f |
55 | sub count_all { shift->count } |
cba994a1 |
56 | # Contributed by Numa. No test for this though. |
57 | |
656796f2 |
58 | 1; |