X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FRetrieve.pm;h=1186ae4583a76066e5c474e55a18af4356ea15d0;hb=915919c594620a5440f01ee2e271c102f7613cc8;hp=6937fb36094aa7ee3fac5566b63db0e1f461ae00;hpb=3125eb1fc9e9dcff0572b1c01cd1a802a9c4862c;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/Retrieve.pm b/lib/DBIx/Class/CDBICompat/Retrieve.pm index 6937fb3..1186ae4 100644 --- a/lib/DBIx/Class/CDBICompat/Retrieve.pm +++ b/lib/DBIx/Class/CDBICompat/Retrieve.pm @@ -1,12 +1,57 @@ -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 } -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.