Alzabo/Runtime.pm

filter: Statementstmt 47.9% 46 / 96 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 68.1% 15 / 22 Podpod 0.0% 0 / 5 totaltotal 29.0% 61 / 210 CC 33 SCAR 51.0
CC
33
Cov
28%
_process_conditions
420.0
process_where_clause
30.0
process_having_clause
30.0
CRAP 163.2
« Alzabo/Runtime/Schema.pm ↑ Summary Alzabo/Runtime/Table.pm »
1 package Alzabo::Runtime;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 ▶use Alzabo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use Alzabo::Runtime::Column;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Alzabo::Runtime::ColumnDefinition;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Alzabo::Runtime::ForeignKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Alzabo::Runtime::Index;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Alzabo::Runtime::InsertHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Alzabo::Runtime::JoinCursor;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Alzabo::Runtime::Row;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use Alzabo::Runtime::RowCursor;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use Alzabo::Runtime::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use Alzabo::Runtime::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use Alzabo::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 11 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 11 $VERSION = 2.0;
22  
23 11 1;
24  
25 sub import
26 15 ▶{
Subroutine import: called CC=2 SCAR=7.6
27 15 shift;
28  
29 # ignore errors and let them be handled later in the app when it
30 # tries to access the schema.
31 0 eval { Alzabo::Runtime::Schema->load_from_file( name => $_ ); } foreach @_;
32 }
33  
34 sub sqlmaker
35 0 ▶{
Subroutine sqlmaker: not called CC=2 SCAR=17.9
Pod undocumented
36 0 my ($schema, $p) = @_;
37  
38 my %sqlmaker_p = ( exists $p->{quote_identifiers} ?
39 0 ▶ ( quote_identifiers => $p->{quote_identifiers} ) :
Branch: 1 branch
BranchTrueFalseTotal
exists $p->{'quote_identifiers'} ? : 0 0 0
40 ()
41 );
42  
43 0 return $schema->sqlmaker(%sqlmaker_p);
44 }
45  
46 sub process_where_clause
47 0 ▶{
Subroutine process_where_clause: not called CC=5 SCAR=34.0
Pod undocumented
48 0 my ($sql, $where) = @_;
49  
50 0 ▶ $where = [ $where ]
Branch: 1 branch
BranchTrueFalseTotal
unless Alzabo::Utils::is_arrayref($where->[0]) or $where->[0] eq "(" 0 0 0
Condition0%0/3
Alzabo::Utils::is_arrayref($where->[0]) or $where->[0] eq "("
l!l&&r!l&&!r
000
MC/DC0%0/2
Alzabo::Utils::is_arrayref($where->[0]) or $where->[0] eq "("
Alzabo::Utils::is_arrayref($where->[0]) $where->[0] eq "("
Truth table0%0/3
A or B
A= Alzabo::Utils::is_arrayref($where->[0])B= $where->[0] eq "("
ABresult
1X1
011
000
51 unless Alzabo::Utils::is_arrayref( $where->[0] ) || $where->[0] eq '(';
52  
53 0 ▶ my $has_where =
Branch: 1 branch
BranchTrueFalseTotal
$sql->last_op eq 'where' || $sql->last_op eq 'condition' ? : 0 0 0
Condition0%0/3
$sql->last_op eq "where" or $sql->last_op eq "condition"
l!l&&r!l&&!r
000
MC/DC0%0/2
$sql->last_op eq "where" or $sql->last_op eq "condition"
$sql->last_op eq "where" $sql->last_op eq "condition"
Truth table0%0/3
A or B
A= $sql->last_op eq "where"B= $sql->last_op eq "condition"
ABresult
1X1
011
000
54 ( $sql->last_op eq 'where' || $sql->last_op eq 'condition' ) ? 1 : 0;
55  
56 0 _process_conditions( $sql, $has_where, $where, 'where' );
57 }
58  
59 sub process_having_clause
60 0 ▶{
Subroutine process_having_clause: not called CC=5 SCAR=34.0
Pod undocumented
61 0 my ($sql, $having) = @_;
62  
63 0 ▶ $having = [ $having ]
Branch: 1 branch
BranchTrueFalseTotal
unless Alzabo::Utils::is_arrayref($having->[0]) or $having->[0] eq "(" 0 0 0
Condition0%0/3
Alzabo::Utils::is_arrayref($having->[0]) or $having->[0] eq "("
l!l&&r!l&&!r
000
MC/DC0%0/2
Alzabo::Utils::is_arrayref($having->[0]) or $having->[0] eq "("
Alzabo::Utils::is_arrayref($having->[0]) $having->[0] eq "("
Truth table0%0/3
A or B
A= Alzabo::Utils::is_arrayref($having->[0])B= $having->[0] eq "("
ABresult
1X1
011
000
64 unless Alzabo::Utils::is_arrayref( $having->[0] ) || $having->[0] eq '(';
65  
66 0 ▶ my $has_having =
Branch: 1 branch
BranchTrueFalseTotal
$sql->last_op eq 'having' || $sql->last_op eq 'condition' ? : 0 0 0
Condition0%0/3
$sql->last_op eq "having" or $sql->last_op eq "condition"
l!l&&r!l&&!r
000
MC/DC0%0/2
$sql->last_op eq "having" or $sql->last_op eq "condition"
$sql->last_op eq "having" $sql->last_op eq "condition"
Truth table0%0/3
A or B
A= $sql->last_op eq "having"B= $sql->last_op eq "condition"
ABresult
1X1
011
000
67 ( $sql->last_op eq 'having' || $sql->last_op eq 'condition' ) ? 1 : 0;
68  
69 0 _process_conditions( $sql, $has_having, $having, 'having' );
70 }
71  
72 sub _process_conditions
73 0 ▶{
Subroutine _process_conditions: not called CC=20 SCAR=60.4
74 0 my ($sql, $has_start, $conditions, $needed_op) = @_;
75  
76 0 ▶ my $needs_op = $sql->last_op eq 'where' || $sql->last_op eq 'having' ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$sql->last_op eq 'where' || $sql->last_op eq 'having' ? : 0 0 0
Condition0%0/3
$sql->last_op eq "where" or $sql->last_op eq "having"
l!l&&r!l&&!r
000
MC/DC0%0/2
$sql->last_op eq "where" or $sql->last_op eq "having"
$sql->last_op eq "where" $sql->last_op eq "having"
Truth table0%0/3
A or B
A= $sql->last_op eq "where"B= $sql->last_op eq "having"
ABresult
1X1
011
000
77  
78 0 ▶ if ($has_start)
Branch: 1 branch
BranchTrueFalseTotal
if ($has_start) 0 0 0
79 {
80 # wrap this in parens in order to protect from interactions with
81 # join clauses
82 0 ▶ $sql->and if $needs_op;
Branch: 1 branch
BranchTrueFalseTotal
if $needs_op 0 0 0
83  
84 0 $sql->subgroup_start;
85  
86 0 $needs_op = 0;
87 }
88  
89 0 my $x = 0;
90 0 foreach my $clause (@$conditions)
91 {
92 0 ▶ if (ref $clause)
Branch: 4 branches
BranchTrueFalseTotal
if (ref $clause) { } 0 0 0
elsif (lc $clause eq 'and' or lc $clause eq 'or') { } 0 0 0
elsif ($clause eq '(') { } 0 0 0
elsif ($clause eq ')') { } 0 0 0
93 {
94 0 ▶ Alzabo::Exception::Params->throw
Branch: 1 branch
BranchTrueFalseTotal
unless Alzabo::Utils::is_arrayref($clause) 0 0 0
95 ( error => "Individual where clause components must be array references" )
96 unless Alzabo::Utils::is_arrayref($clause);
97  
98 0 ▶ Alzabo::Exception::Params->throw
Branch: 1 branch
BranchTrueFalseTotal
unless @$clause 0 0 0
99 ( error => "Individual where clause components cannot be empty" )
100 unless @$clause;
101  
102 0 ▶ if ($needs_op)
Branch: 1 branch
BranchTrueFalseTotal
if ($needs_op) 0 0 0
103 {
104 0 ▶ my $op = $x || $has_start ? 'and' : $needed_op;
Branch: 1 branch
BranchTrueFalseTotal
$x || $has_start ? : 0 0 0
Condition0%0/3
$x or $has_start
l!l&&r!l&&!r
000
MC/DC0%0/2
$x or $has_start
$x $has_start
Truth table0%0/3
A or B
A= $xB= $has_start
ABresult
1X1
011
000
105 0 $sql->$op();
106 }
107  
108 0 $sql->condition(@$clause);
109 0 $needs_op = 1;
110 }
111 ▶ elsif (lc $clause eq 'and' || lc $clause eq 'or')
Condition0%0/3
lc $clause eq "and" or lc $clause eq "or"
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $clause eq "and" or lc $clause eq "or"
lc $clause eq "and" lc $clause eq "or"
Truth table0%0/3
A or B
A= lc $clause eq "and"B= lc $clause eq "or"
ABresult
1X1
011
000
112 {
113 0 $sql->$clause();
114 0 $needs_op = 0;
115 0 next;
116 }
117 elsif ($clause eq '(')
118 {
119 0 ▶ if ($needs_op)
Branch: 1 branch
BranchTrueFalseTotal
if ($needs_op) 0 0 0
120 {
121 0 ▶ my $op = $x || $has_start ? 'and' : $needed_op;
Branch: 1 branch
BranchTrueFalseTotal
$x || $has_start ? : 0 0 0
Condition0%0/3
$x or $has_start
l!l&&r!l&&!r
000
MC/DC0%0/2
$x or $has_start
$x $has_start
Truth table0%0/3
A or B
A= $xB= $has_start
ABresult
1X1
011
000
122 0 $sql->$op();
123 }
124 0 $sql->subgroup_start;
125 0 $needs_op = 0;
126 }
127 elsif ($clause eq ')')
128 {
129 0 $sql->subgroup_end;
130 0 $needs_op = 1;
131 }
132 else
133 {
134 0 Alzabo::Exception::Params->throw( error => "Invalid where clause specification: $clause" );
135 }
136 0 $x++;
137 }
138  
139 0 ▶ $sql->subgroup_end if $has_start;
Branch: 1 branch
BranchTrueFalseTotal
if $has_start 0 0 0
140 }
141  
142 sub process_order_by_clause
143 0 ▶{
Subroutine process_order_by_clause: not called CC=1 SCAR=6.9
Pod undocumented
144 0 _process_by_clause(@_, 'order');
145 }
146  
147 sub process_group_by_clause
148 0 ▶{
Subroutine process_group_by_clause: not called CC=1 SCAR=6.9
Pod undocumented
149 0 _process_by_clause(@_, 'group');
150 }
151  
152 sub _process_by_clause
153 0 ▶{
Subroutine _process_by_clause: not called CC=4 SCAR=30.0
154 0 my ($sql, $by, $type) = @_;
155  
156 0 my @items;
157 0 ▶ if ( Alzabo::Utils::safe_isa( $by, 'Alzabo::Column' ) || Alzabo::Utils::safe_isa( $by, 'Alzabo::SQLMaker::Function' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (Alzabo::Utils::safe_isa($by, 'Alzabo::Column') or Alzabo::Utils::safe_isa($by, 'Alzabo::SQLMaker::Function')) { } 0 0 0
elsif (Alzabo::Utils::is_arrayref($by)) { } 0 0 0
Condition0%0/3
Alzabo::Utils::safe_isa($by, "Alzabo::Column") or Alzabo::Utils::safe_isa($by, "Alzabo::SQLMaker::Function")
l!l&&r!l&&!r
000
MC/DC0%0/2
Alzabo::Utils::safe_isa($by, "Alzabo::Column") or Alzabo::Utils::safe_isa($by, "Alzabo::SQLMaker::Function")
Alzabo::Utils::safe_isa($by, "Alzabo::Column") Alzabo::Utils::safe_isa($by, "Alzabo::SQLMaker::Function")
Truth table0%0/3
A or B
A= Alzabo::Utils::safe_isa($by, "Alzabo::Column")B= Alzabo::Utils::safe_isa($by, "Alzabo::SQLMaker::Function")
ABresult
1X1
011
000
158 {
159 0 @items = $by;
160 }
161 elsif ( Alzabo::Utils::is_arrayref($by) )
162 {
163 0 @items = @$by;
164 }
165  
166 0 my $method = "${type}_by";
167 0 $sql->$method(@items);
168 }
169  
170  
171  
172 __END__
« Alzabo/Runtime/Schema.pm ↑ Summary Alzabo/Runtime/Table.pm »