X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FRetrieve.pm;h=1186ae4583a76066e5c474e55a18af4356ea15d0;hb=3bec1f52a1c0b65a7f323799a9ea832bf4b6695e;hp=3259bb25b63ae83e9d78a1685bc6dc9d90e61369;hpb=716b3d29720debadf5b4f4d964d6b0076f8e39f6;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/Retrieve.pm b/lib/DBIx/Class/CDBICompat/Retrieve.pm index 3259bb2..1186ae4 100644 --- a/lib/DBIx/Class/CDBICompat/Retrieve.pm +++ b/lib/DBIx/Class/CDBICompat/Retrieve.pm @@ -1,12 +1,48 @@ -package DBIx::Class::CDBICompat::Retrieve; +package # hide from PAUSE + DBIx::Class::CDBICompat::Retrieve; use strict; use warnings FATAL => 'all'; -sub retrieve { - die "No args to retrieve" unless @_ > 1; - shift->find(@_); +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 {