Minor doc patch by Caelum
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / Retrieve.pm
CommitLineData
c0e7b4e5 1package # hide from PAUSE
2 DBIx::Class::CDBICompat::Retrieve;
656796f2 3
4use strict;
5use warnings FATAL => 'all';
6
716b3d29 7
9387c904 8sub 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
30sub 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
42sub _build_query {
43 my ($self, $query) = @_;
44
45 return $query;
716b3d29 46}
6009260a 47
48sub retrieve_from_sql {
49 my ($class, $cond, @rest) = @_;
e60dc79f 50
6009260a 51 $cond =~ s/^\s*WHERE//i;
e60dc79f 52
53 if( $cond =~ s/\bLIMIT (\d+)\s*$//i ) {
54 push @rest, { rows => $1 };
55 }
56
57 return $class->search_literal($cond, @rest);
58}
59
60sub construct {
61 my $class = shift;
62 my $obj = $class->resultset_instance->new_result(@_);
63 $obj->in_storage(1);
64
65 return $obj;
6009260a 66}
656796f2 67
716b3d29 68sub retrieve_all { shift->search }
3125eb1f 69sub count_all { shift->count }
e60dc79f 70
71sub maximum_value_of {
72 my($class, $col) = @_;
73 return $class->resultset_instance->get_column($col)->max;
74}
75
76sub minimum_value_of {
77 my($class, $col) = @_;
78 return $class->resultset_instance->get_column($col)->min;
79}
cba994a1 80
656796f2 811;