From: Peter Rabbitson Date: Mon, 8 Nov 2010 01:26:47 +0000 (+0100) Subject: Die on search in void context X-Git-Tag: v0.08125~66 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0e7a447e570daf41c11b403fd81046756894cc27;p=dbsrgits%2FDBIx-Class.git Die on search in void context --- diff --git a/Changes b/Changes index 2acf103..58a6f70 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,8 @@ Revision history for DBIx::Class * New Features / Changes - New method ResultSource columns_info method, returning multiple pairs of column name/info at once + - $rs->search now throws when called in void context, as it makes + no sense (and is nearly always a sign of a bug/misdesign) - NULL is now supplied unquoted to all debug-objects, in order to differentiate between a real NULL and the string 'NULL' diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 474b5da..c6a68c3 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -249,7 +249,17 @@ For more help on using joins with search, see L. sub search { my $self = shift; my $rs = $self->search_rs( @_ ); - return (wantarray ? $rs->all : $rs); + + my $want = wantarray; + if ($want) { + return $rs->all; + } + elsif (defined $want) { + return $rs; + } + else { + $self->throw_exception ('->search is *not* a mutator, calling it in void context makes no sense'); + } } =head2 search_rs diff --git a/t/search/void.t b/t/search/void.t new file mode 100644 index 0000000..95a040f --- /dev/null +++ b/t/search/void.t @@ -0,0 +1,16 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(no_deploy => 1); + +throws_ok { + $schema->resultset('Artist')->search +} qr/\Qsearch is *not* a mutator/, 'Proper exception on search in void ctx'; + +done_testing; diff --git a/t/storage/txn.t b/t/storage/txn.t index a6a5f0b..dc7c8b3 100644 --- a/t/storage/txn.t +++ b/t/storage/txn.t @@ -18,7 +18,7 @@ my $code = sub { year => 2006, }) foreach (@cd_titles); - return $artist->cds; + return $artist->cds->all; }; # Test checking of parameters