File Coverage

blib/lib/DBIx/Class/Helper/ResultSet/IgnoreWantarray.pm
Criterion Covered Total %
statement 14 14 100.0
branch 1 2 50.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 1 1 100.0
total 23 25 92.0


line stmt bran cond sub pod time code
1             package DBIx::Class::Helper::ResultSet::IgnoreWantarray;
2             $DBIx::Class::Helper::ResultSet::IgnoreWantarray::VERSION = '2.034002';
3             # ABSTRACT: Get rid of search context issues
4              
5 55     55   201572 use strict;
  55         124  
  55         1286  
6 55     55   243 use warnings;
  55         97  
  55         1167  
7              
8 55     55   238 use parent 'DBIx::Class::ResultSet';
  55         101  
  55         248  
9              
10             sub search :DBIC_method_is_indirect_sugar{
11 415 50 66 415 1 223743 $_[0]->throw_exception ('->search is *not* a mutator, calling it in void context makes no sense')
12             if !defined wantarray && (caller)[0] !~ /^\QDBIx::Class::/;
13              
14 414         1535 shift->search_rs(@_);
15 55     55   31412 }
  55         56454  
  55         276  
16              
17             1;
18              
19             __END__
20              
21             =pod
22              
23             =head1 NAME
24              
25             DBIx::Class::Helper::ResultSet::IgnoreWantarray - Get rid of search context issues
26              
27             =head1 SYNOPSIS
28              
29             package MyApp::Schema::ResultSet::Foo;
30              
31             __PACKAGE__->load_components(qw{Helper::ResultSet::IgnoreWantarray});
32              
33             ...
34              
35             1;
36              
37             And then else where, like in a controller:
38              
39             my $rs = $self->paginate(
40             $schema->resultset('Foo')->search({
41             name => 'frew'
42             })
43             );
44              
45             =head1 DESCRIPTION
46              
47             This component makes search always return a ResultSet, instead of
48             returning an array of your database in array context. See
49             L<DBIx::Class::Helper::ResultSet/NOTE> for a nice way to apply it to your
50             entire schema.
51              
52             =head1 METHODS
53              
54             =head2 search
55              
56             Override of the default search method to force it to return a ResultSet.
57              
58             =head1 AUTHOR
59              
60             Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
61              
62             =head1 COPYRIGHT AND LICENSE
63              
64             This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
65              
66             This is free software; you can redistribute it and/or modify it under
67             the same terms as the Perl 5 programming language system itself.
68              
69             =cut