File Coverage

blib/lib/DBIx/Class/Helper/ResultSet/Shortcut/ResultsExist.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 25 27 92.5


line stmt bran cond sub pod time code
1             package DBIx::Class::Helper::ResultSet::Shortcut::ResultsExist;
2             $DBIx::Class::Helper::ResultSet::Shortcut::ResultsExist::VERSION = '2.034002';
3 56     56   20406 use strict;
  56         121  
  56         1255  
4 56     56   240 use warnings;
  56         107  
  56         1154  
5              
6 56     56   244 use parent 'DBIx::Class::ResultSet';
  56         133  
  56         276  
7              
8             sub results_exist_as_query {
9 4     4 0 81 my $self = shift;
10              
11              
12 4         17 my $reified = $self->search_rs( {}, {
13             columns => { _results_existence_check => \ '42' }
14             } )->as_query;
15              
16              
17 4         5047 $$reified->[0] = "( SELECT EXISTS $$reified->[0] )";
18              
19              
20 4         93 $reified;
21             }
22              
23              
24             sub results_exist {
25 2     2 0 64 my $self = shift;
26              
27 2         14 my $query = $self->results_exist_as_query;
28 2         5 $$query->[0] .= ' AS _existence_subq';
29              
30 2         11 my( undef, $sth ) = $self->result_source
31             ->schema
32             ->storage
33             ->_select(
34             $query,
35             \'*',
36             {},
37             {},
38             );
39              
40 2 100       1662 $sth->fetchall_arrayref->[0][0] ? 1 : 0;
41             }
42              
43             1;
44              
45             __END__
46              
47             =pod
48              
49             =head1 NAME
50              
51             DBIx::Class::Helper::ResultSet::Shortcut::ResultsExist
52              
53             =head1 AUTHOR
54              
55             Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
56              
57             =head1 COPYRIGHT AND LICENSE
58              
59             This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
60              
61             This is free software; you can redistribute it and/or modify it under
62             the same terms as the Perl 5 programming language system itself.
63              
64             =cut