Helper/ResultSet/SetOperations.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 78.5% 11 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 84.6% 11 / 13 Podpod 100% 6 / 6 totaltotal 87.9% 73 / 83 CC 10 SCAR 10.5
CC
10
Cov
90%
_set_operation
5.0
_compare_arrays
4.0
_except_keyword
3.2
CRAP 2.8
« Helper/ResultSet/Errors.pm ↑ Summary Helper/ResultSet/Util.pm »
1 package DBIx::Class::Helper::ResultSet::SetOperations;
2 56 $DBIx::Class::Helper::ResultSet::SetOperations::VERSION = '2.037000';
3 # ABSTRACT: Do set operations with DBIx::Class
4  
5 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 56 ▶use parent 'DBIx::Class::ResultSet';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # cribbed from perlfaq4
11 38 ▶sub _compare_arrays {
Subroutine _compare_arrays: called CC=4 SCAR=13.9
12 38 my ($self, $first, $second) = @_;
13  
14 56 ▶ no warnings; # silence spurious -w undef complaints
Subroutine BEGIN: called CC=1 SCAR=0.0
15 38 ▶ return 0 unless @$first == @$second;
Branch: 1 branch
BranchTrueFalseTotal
unless @$first == @$second 1 37 38
16 37 ▶ for (my $i = 0; $i < @$first; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$first) 74 37 111
17 74 ▶ return 0 if $first->[$i] ne $second->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $first->[$i] ne $second->[$i] 0 74 74
18 }
19 37 return 1;
20 }
21  
22 7 ▶sub union {
Subroutine union: called CC=1 SCAR=0.0
Pod documented
23 7 shift->_set_operation( UNION => @_ );
24 }
25  
26 2 ▶sub union_all {
Subroutine union_all: called CC=1 SCAR=0.0
Pod documented
27 2 shift->_set_operation( "UNION ALL" => @_ );
28 }
29  
30 5 ▶sub intersect {
Subroutine intersect: called CC=1 SCAR=0.0
Pod documented
31 5 shift->_set_operation( INTERSECT => @_ );
32 }
33  
34 0 ▶sub intersect_all {
Subroutine intersect_all: not called CC=1 SCAR=6.9
Pod documented
35 0 shift->_set_operation( "INTERSECT ALL" => @_ );
36 }
37  
38 6 ▶sub _except_keyword {
Subroutine _except_keyword: called CC=3 SCAR=11.7
39 6 my $self = shift;
40  
41 6 ▶ $self->{_except_keyword} ||= ( $self->result_source->schema->storage->sqlt_type eq 'Oracle' ? "MINUS" : "EXCEPT" );
Branch: 1 branch
BranchTrueFalseTotal
$self->result_source->schema->storage->sqlt_type eq 'Oracle' ? : 0 3 3
Condition66%2/3
$self->{"_except_keyword"} ||= $self->result_source->schema->storage->sqlt_type eq "Oracle" ? "MINUS" : "EXCEPT"
l!l&&r!l&&!r
330
MC/DC0%0/2
$self->{"_except_keyword"} ||= $self->result_source->schema->storage->sqlt_type eq "Oracle" ? "MINUS" : "EXCEPT"
$self->{"_except_keyword"} $self->result_source->schema->storage->sqlt_type eq "Oracle" ? "MINUS" : "EXCEPT"
Truth table66%2/3
A ||= B
A= $self->{"_except_keyword"}B= $self->result_source->schema->storage->sqlt_type eq "Oracle" ? "MINUS" : "EXCEPT"
ABresult
1X1
011
000
42 }
43  
44 6 ▶sub except {
Subroutine except: called CC=1 SCAR=0.0
Pod documented
45 6 my ( $self, @args ) = @_;
46 6 $self->_set_operation( $self->_except_keyword => @args );
47 }
48  
49 0 ▶sub except_all {
Subroutine except_all: not called CC=1 SCAR=6.9
Pod documented
50 # not supported on most DBs
51 0 shift->_set_operation( "EXCEPT ALL" => @_ );
52 }
53  
54 20 ▶sub _set_operation {
Subroutine _set_operation: called CC=5 SCAR=16.1
55 20 my ( $self, $operation, $other ) = @_;
56  
57 20 my @sql;
58 my @params;
59  
60 20 my $as = $self->_resolved_attrs->{as};
61  
62 20 ▶ my @operands = ( $self, ref $other eq 'ARRAY' ? @$other : $other );
Branch: 1 branch
BranchTrueFalseTotal
ref $other eq 'ARRAY' ? : 0 20 20
63  
64 20 for (@operands) {
65 40 ▶ $self->throw_exception("ResultClass of ResultSets do not match!")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->result_class eq $_->result_class 2 38 40
66 unless $self->result_class eq $_->result_class;
67  
68 38 my $attrs = $_->_resolved_attrs;
69  
70 $self->throw_exception('ResultSets do not all have the same selected columns!')
71 38 ▶ unless $self->_compare_arrays($as, $attrs->{as});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_compare_arrays($as, $attrs->{"as"}) 1 37 38
72  
73 37 my ($sql, @bind) = @{${$_->as_query}};
74 37 $sql =~ s/^\s*\((.*)\)\s*$/$1/;
75  
76 37 push @sql, $sql;
77 37 push @params, @bind;
78 }
79  
80 17 my $query = q<(> . join(" $operation ", @sql). q<)>;
81  
82 17 my $attrs = $self->_resolved_attrs;
83 return $self->result_source->resultset->search(undef, {
84 alias => $self->current_source_alias,
85 from => [{
86 $self->current_source_alias => \[ $query, @params ],
87 -alias => $self->current_source_alias,
88 -source_handle => $self->result_source->handle,
89 }],
90 columns => $attrs->{as},
91 17 result_class => $self->result_class,
92 });
93 }
94  
95 56 1;
96  
97 __END__
« Helper/ResultSet/Errors.pm ↑ Summary Helper/ResultSet/Util.pm »