Skip to content

Commit

Permalink
Make IgnoreWantarray's search die in void context
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Feb 14, 2014
1 parent 6eb7efb commit 05ccca7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- Make IgnoreWantarray's search die in void context

2.019003 2014-02-07 22:21:47-06:00 America/Chicago
- Fix ->copy on rows with proxied ResultSet methods (thanks moltar for the
Expand Down
3 changes: 3 additions & 0 deletions lib/DBIx/Class/Helper/ResultSet/IgnoreWantarray.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use warnings;
# ABSTRACT: Get rid of search context issues

sub search {
$_[0]->throw_exception ('->search is *not* a mutator, calling it in void context makes no sense')
if !defined wantarray && (caller)[0] !~ /^\QDBIx::Class::/;

shift->search_rs(@_);
}

Expand Down
5 changes: 5 additions & 0 deletions t/resultset/ignore-wantarray.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;

use lib 't/lib';
use Test::More;
use Test::Fatal;

use TestSchema;
my $schema = TestSchema->deploy_or_connect();
Expand All @@ -20,4 +21,8 @@ isa_ok $rs2, 'DBIx::Class::ResultSet';
isa_ok $rs3, 'DBIx::Class::ResultSet';
isa_ok $rs4, 'DBIx::Class::ResultSet';

like(exception {
$schema->resultset('Bar')->search
}, qr/search is \*not\* a mutator/, 'correctly die in void ctx');

done_testing;

0 comments on commit 05ccca7

Please sign in to comment.