Fey/Role/SetOperation.pm

filter: Statementstmt 89.4% 68 / 76 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 3 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 88.8% 16 / 18 Podpod 25.0% 1 / 4 totaltotal 82.4% 94 / 114 CC 11 SCAR 6.7
CC
11
Cov
85%
__ANON__
3.2
except
3.2
intersect
3.2
CRAP 1.9
« Fey/Literal.pm ↑ Summary Fey/Role/SQL/HasWhereClause.pm »
1 package Fey::Role::SetOperation;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 16 our $VERSION = '0.44';
8  
9 27 ▶use Fey::Types qw( ArrayRef Bool SetOperationArg Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 27 ▶use MooseX::Role::Parameterized 1.00;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use MooseX::Params::Validate 0.21 qw( pos_validated_list );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 16 parameter keyword => (
15 isa => Str,
16 required => 1,
17 );
18  
19 16 with 'Fey::Role::Comparable',
20 'Fey::Role::SQL::HasOrderByClause',
21 'Fey::Role::SQL::HasLimitClause',
22 'Fey::Role::SQL::ReturnsData';
23  
24 16 has 'is_all' => (
25 is => 'rw',
26 isa => Bool,
27 default => 0,
28 writer => '_set_is_all',
29 );
30  
31 has '_set_elements' => (
32 traits => ['Array'],
33 is => 'bare',
34 isa => ArrayRef [SetOperationArg],
35 25 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 16 handles => {
37 _add_set_elements => 'push',
38 _set_element_count => 'count',
39 _set_elements => 'elements',
40 },
41 init_arg => undef,
42 );
43  
44 3 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod undocumented
45 3 return $_[0]->sql('Fey::FakeDBI');
46 }
47  
48 3 ▶sub all {
Subroutine all: called CC=1 SCAR=0.0
Pod documented
49 3 $_[0]->_set_is_all(1);
50 3 return $_[0];
51 }
52  
53 1 ▶sub bind_params {
Subroutine bind_params: called CC=1 SCAR=0.0
Pod undocumented
54 1 my $self = shift;
55 1 return map { $_->bind_params } $self->_set_elements();
56 }
57  
58 0 ▶sub select_clause_elements {
Subroutine select_clause_elements: not called CC=1 SCAR=6.9
Pod undocumented
59 0 return ( $_[0]->_set_elements() )[0]->select_clause_elements();
60 }
61  
62 81 ▶role {
Subroutine __ANON__: called CC=1 SCAR=0.1
63 81 my $p = shift;
64 81 my %extra = @_;
65  
66 81 my $name = lc $p->keyword();
67  
68 28 ▶ method 'keyword_clause' => sub {
Subroutine keyword_clause: called CC=2 SCAR=7.0
Subroutine __ANON__: not called CC=2 SCAR=7.0
69 28 my $self = shift;
70  
71 28 my $sql = uc($name);
72 28 ▶ $sql .= ' ALL' if $self->is_all();
Branch: 2 branches
BranchTrueFalseTotal
if $self->is_all 3 25 28
if $self->is_all 0 0 0
73 28 return $sql;
74 81 };
75  
76 81 my $clause_method = $name . '_clause';
77  
78 27 ▶ method 'sql' => sub {
Subroutine sql: called CC=1 SCAR=0.0
79 27 my $self = shift;
80 27 my $dbh = shift;
81  
82 return (
83 27 join q{ },
84 $self->$clause_method($dbh),
85 $self->order_by_clause($dbh),
86 $self->limit_clause($dbh),
87 );
88 81 };
89  
90 37 ▶ method $name => sub {
Subroutine except: called CC=3 SCAR=11.8
91 37 my $self = shift;
92  
93 37 my $count = @_;
94 37 ▶ $count = 2
Branch: 1 branch
BranchTrueFalseTotal
if $count < 2 and $self->_set_element_count < 2 9 28 37
Condition50%3/6
$count < 2 and $self->_set_element_count < 2
!ll&&!rl&&r
2269
$count < 2 and $self->_set_element_count < 2
!ll&&!rl&&r
000
MC/DC100%2/2
$count < 2 and $self->_set_element_count < 2
$count < 2 $self->_set_element_count < 2
MC/DC0%0/2
$count < 2 and $self->_set_element_count < 2
$count < 2 $self->_set_element_count < 2
Truth table100%3/3
A and B
A= $count < 2B= $self->_set_element_count < 2
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $count < 2B= $self->_set_element_count < 2
ABresult
0X0
100
111
95 if $count < 2 && $self->_set_element_count() < 2;
96  
97 0 my (@set) = pos_validated_list(
98 \@_,
99 ( ( { isa => SetOperationArg } ) x $count ),
100 MX_PARAMS_VALIDATE_NO_CACHE => 1,
101 );
102  
103 0 $self->_add_set_elements(@set);
104  
105 0 return $self;
106 81 };
107  
108 28 ▶ method $clause_method => sub {
Subroutine intersect_clause: called CC=1 SCAR=0.5
Subroutine union_clause: called CC=1 SCAR=0.5
109 0 my $self = shift;
110 0 my $dbh = shift;
111  
112 return (
113 join q{ } . $self->keyword_clause($dbh) . q{ },
114 0 map { '(' . $_->sql($dbh) . ')' } $self->_set_elements()
115 );
116 81 };
117  
118 81 with 'Fey::Role::HasAliasName' => {
119 generated_alias_prefix => uc $name,
120 sql_needs_parens => 1,
121 };
122 16 };
123  
124 16 1;
125  
126 # ABSTRACT: A role for things that are a set operation
127  
128 __END__
« Fey/Literal.pm ↑ Summary Fey/Role/SQL/HasWhereClause.pm »