X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FRetrieve.pm;h=1186ae4583a76066e5c474e55a18af4356ea15d0;hb=9387c9042568a6c4dcc8e197f0000e7c7c4bbf13;hp=b7fca68fd8160285ad7f6c60a2ed61a9cbf61873;hpb=656796f2088da66cc80f4eb127c39c923ef3c1dd;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/Retrieve.pm b/lib/DBIx/Class/CDBICompat/Retrieve.pm index b7fca68..1186ae4 100644 --- a/lib/DBIx/Class/CDBICompat/Retrieve.pm +++ b/lib/DBIx/Class/CDBICompat/Retrieve.pm @@ -1,10 +1,58 @@ -package DBIx::Class::CDBICompat::Retrieve; +package # hide from PAUSE + DBIx::Class::CDBICompat::Retrieve; use strict; use warnings FATAL => 'all'; -sub retrieve { shift->find(@_) } -sub retrieve_all { shift->search_literal('1') } -sub retrieve_from_sql { shift->search_literal(@_) } + +sub retrieve { + my $self = shift; + die "No args to retrieve" unless @_ > 0; + + my @cols = $self->primary_columns; + + my $query; + if (ref $_[0] eq 'HASH') { + $query = { %{$_[0]} }; + } + elsif (@_ == @cols) { + $query = {}; + @{$query}{@cols} = @_; + } + else { + $query = {@_}; + } + + $query = $self->_build_query($query); + $self->find($query); +} + +sub find_or_create { + my $self = shift; + my $query = ref $_[0] eq 'HASH' ? shift : {@_}; + + $query = $self->_build_query($query); + $self->next::method($query); +} + +# _build_query +# +# Build a query hash. Defaults to a no-op; ColumnCase overrides. + +sub _build_query { + my ($self, $query) = @_; + + return $query; +} + +sub retrieve_from_sql { + my ($class, $cond, @rest) = @_; + $cond =~ s/^\s*WHERE//i; + $class->search_literal($cond, @rest); +} + +sub retrieve_all { shift->search } +sub count_all { shift->count } + # Contributed by Numa. No test for this though. 1;