lib/TSQL/AST/SQLIfStatement.pm

filter: Statementstmt 82.9% 102 / 123 Branchbran 55.8% 19 / 34 Conditioncond 71.4% 15 / 21 MC/DCmcdc 57.1% 8 / 14 Subroutinesub 95.0% 19 / 20 Podpod n/a totaltotal 76.8% 163 / 212 CC 25 SCAR 21.6
CC
25
Cov
76%
__ANON__
13.7
_HandleElse
13.4
__ANON__
13.4
CRAP 8.7
↑ Summary lib/TSQL/AST/SQLTryCatchBlock.pm »
1 4 ▶use MooseX::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 ▶class TSQL::AST::SQLIfStatement extends TSQL::AST::SQLStatement {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.2
5  
6 4 ▶use TSQL::AST::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use TSQL::AST::SQLConditionalExpression;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 #use TSQL::AST::SQLFragment;
9 #use TSQL::AST::SQLStatement;
10 4 ▶use TSQL::AST::SQLStatementBlock;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use TSQL::AST::SQLTryCatchBlock;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use TSQL::AST::SQLWhileStatement;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 =head1 NAME
17  
18 TSQL::AST::SQLIfStatement - Represents a TSQL If Statement.
19  
20 =head1 VERSION
21  
22 Version 0.02
23  
24 =cut
25  
26 #our \$VERSION = '0.02';
27  
28 4 ▶use feature "switch";
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 4 has 'condition' => (
33 is => 'rw',
34 isa => 'TSQL::AST::SQLConditionalExpression',
35 );
36  
37  
38 4 has 'ifBranch' => (
39 is => 'rw',
40 isa => 'TSQL::AST::SQLStatement',
41 );
42  
43  
44 4 has 'elseBranch' => (
45 is => 'rw',
46 isa => 'TSQL::AST::SQLStatement',
47 );
48  
49  
50 0 ▶method _HandleElse ( ScalarRef[TSQL::AST::SQLStatement] $block, ScalarRef[Int] $index, ArrayRef[Str] $input, ScalarRef[Bool] $if, ScalarRef[Bool] $else, Bool $advanceIndex) {
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=7 SCAR=26.0
Subroutine _HandleElse: called CC=7 SCAR=26.0
51  
52 0 my $end = 0 ;
53 0 ▶ if ( $$if ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$if) { } 0 0 0
if ($$if) { } 10 7 17
54 0 $self->ifBranch($$block);
55 0 $$if = 0 ;
56 0 ▶ $$index++ if $advanceIndex ;
Branch: 2 branches
BranchTrueFalseTotal
if $advanceIndex 0 0 0
if $advanceIndex 7 3 10
57 0 ▶ if ($$index <= $#{$input}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$index <= $#{$input;}) 0 0 0
if ($$index <= $#{$input;}) 9 1 10
58 0 my $ln = $$input[$$index];
59 0 my $t = TSQL::AST::Factory->makeToken($ln);
60 0 ▶ if ( defined $t && $t->isa('TSQL::AST::Token::Else')) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $t and $t->isa('TSQL::AST::Token::Else')) { } 0 0 0
if (defined $t and $t->isa('TSQL::AST::Token::Else')) { } 7 2 9
Condition33%2/6
defined $t and $t->isa("TSQL::AST::Token::Else")
!ll&&!rl&&r
000
defined $t and $t->isa("TSQL::AST::Token::Else")
!ll&&!rl&&r
207
MC/DC0%0/2
defined $t and $t->isa("TSQL::AST::Token::Else")
defined $t $t->isa("TSQL::AST::Token::Else")
MC/DC50%1/2
defined $t and $t->isa("TSQL::AST::Token::Else")
defined $t $t->isa("TSQL::AST::Token::Else")
Truth table0%0/3
A and B
A= defined $tB= $t->isa("TSQL::AST::Token::Else")
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= defined $tB= $t->isa("TSQL::AST::Token::Else")
ABresult
0X0
100
111
61 0 ▶ $$index++ unless $advanceIndex ;;
Branch: 2 branches
BranchTrueFalseTotal
unless $advanceIndex 0 0 0
unless $advanceIndex 3 4 7
62 0 $$else = 1 ;
63 }
64 else {
65 0 $end = 1 ;
66 }
67 }
68 }
69 else {
70 0 $self->elseBranch($$block);
71 0 $$else = 0 ;
72 }
73 0 return scalar $end ;
74 4 }
75  
76  
77  
78 4 ▶override parse ( ScalarRef[Int] $index, ArrayRef[Str] $input) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=13 SCAR=26.1
79  
80 10 my $if = 1 ;
81 10 my $else = 0;
82
83 10 ▶ while ( $$index <= $#{$input} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$index <= $#{$input;}) 24 1 25
84
85 24 ▶ if ($if==0 && $else==0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($if == 0 and $else == 0) 7 17 24
Condition100%3/3
$if == 0 and $else == 0
!ll&&!rl&&r
1077
MC/DC100%2/2
$if == 0 and $else == 0
$if == 0 $else == 0
Truth table100%3/3
A and B
A= $if == 0B= $else == 0
ABresult
0X0
100
111
86 7 last ;
87 }
88
89 17 my $ln = $$input[$$index];
90 17 my $t = TSQL::AST::Factory->makeToken($ln);
91  
92 #warn Dumper 'PARSEIF', $ln, $$index;
93 #warn Dumper 'PARSEIF', $t;
94  
95 17 given ($t) {
96 17 ▶ when ( defined $_ && $_->isa('TSQL::AST::Token::Begin') ) {
Condition100%3/3
defined $_ && $_->isa('TSQL::AST::Token::Begin')
!ll&&!rl&&r
1034
MC/DC100%2/2
defined $_ && $_->isa('TSQL::AST::Token::Begin')
defined $_ $_->isa('TSQL::AST::Token::Begin')
Truth table100%3/3
A && B
A= defined $_B= $_->isa('TSQL::AST::Token::Begin')
ABresult
0X0
100
111
97 4 $$index++;
98 4 my $block = TSQL::AST::SQLStatementBlock->new( statements => [] ) ;
99 4 $block->parse($index,$input);
100 4 my $stop = $self->_HandleElse(\$block, $index, $input, \$if, \$else, 0);
101 4 ▶ last if $stop;
Branch: 1 branch
BranchTrueFalseTotal
if $stop 0 4 4
102 }
103 13 ▶ when ( defined $_ && $_->isa('TSQL::AST::Token::BeginTry') ) {
Condition100%3/3
defined $_ && $_->isa('TSQL::AST::Token::BeginTry')
!ll&&!rl&&r
1021
MC/DC100%2/2
defined $_ && $_->isa('TSQL::AST::Token::BeginTry')
defined $_ $_->isa('TSQL::AST::Token::BeginTry')
Truth table100%3/3
A && B
A= defined $_B= $_->isa('TSQL::AST::Token::BeginTry')
ABresult
0X0
100
111
104 1 $$index++;
105 1 my $block = TSQL::AST::SQLTryCatchBlock->new( tryBlock => [],catchBlock => [] ) ;
106 1 $block->parse($index,$input);
107 1 my $stop = $self->_HandleElse(\$block, $index, $input, \$if, \$else, 0);
108 1 ▶ last if $stop;
Branch: 1 branch
BranchTrueFalseTotal
if $stop 0 1 1
109 }
110 12 ▶ when ( defined $_ && $_->isa('TSQL::AST::Token::If') ) {
Condition66%2/3
defined $_ && $_->isa('TSQL::AST::Token::If')
!ll&&!rl&&r
1020
MC/DC0%0/2
defined $_ && $_->isa('TSQL::AST::Token::If')
defined $_ $_->isa('TSQL::AST::Token::If')
Truth table66%2/3
A && B
A= defined $_B= $_->isa('TSQL::AST::Token::If')
ABresult
0X0
100
111
111 0 my $block = TSQL::AST::Factory->makeIfStatement($ln);
112 0 $block->parse($index,$input);
113 0 my $stop = $self->_HandleElse(\$block, $index, $input, \$if, \$else, 1);
114 0 ▶ last if $stop;
Branch: 1 branch
BranchTrueFalseTotal
if $stop 0 0 0
115 }
116 12 ▶ when ( defined $_ && $_->isa('TSQL::AST::Token::While') ) {
Condition66%2/3
defined $_ && $_->isa('TSQL::AST::Token::While')
!ll&&!rl&&r
1002
MC/DC50%1/2
defined $_ && $_->isa('TSQL::AST::Token::While')
defined $_ $_->isa('TSQL::AST::Token::While')
Truth table66%2/3
A && B
A= defined $_B= $_->isa('TSQL::AST::Token::While')
ABresult
0X0
100
111
117 2 $$index++;
118 2 my $block = TSQL::AST::Factory->makeWhileStatement($ln);
119 2 $block->parse($index,$input);
120 2 my $stop = $self->_HandleElse(\$block, $index, $input, \$if, \$else, 1);
121 2 ▶ last if $stop;
Branch: 1 branch
BranchTrueFalseTotal
if $stop 0 2 2
122 }
123  
124 10 default {
125 10 my $statement = TSQL::AST::Factory->makeStatement($ln);
126 10 my $stop = $self->_HandleElse(\$statement, $index, $input, \$if, \$else, 1);
127 10 ▶ last if $stop;
Branch: 1 branch
BranchTrueFalseTotal
if $stop 2 8 10
128  
129 8 $$index++;
130 }
131 }
132 }
133 #warn Dumper "IF end", $$index;
134 4 return $self ;}
135  
136 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
137  
138  
139 4 1;
140  
141  
142  
143  
144 =head1 SYNOPSIS
145  
146 Represents the parsed version/AST of a TSQL If Statement.
147  
148 =head1 DESCRIPTION
149  
150 See TSQL::AST.
151  
152 =head1 DEPENDENCIES
153  
154 See TSQL::AST.
155  
156 =head1 AUTHOR
157  
158 Ded MedVed, C<< <dedmedved at cpan.org> >>
159  
160 =head1 BUGS
161  
162 See TSQL::AST.
163  
164 =head1 METHODS
165  
166 =head2 C<new>
167  
168 =over 4
169  
170 =item * C<< TSQL::AST::SQLIfStatement->new() >>
171  
172 =back
173  
174 It creates and returns a new TSQL::AST::SQLIfStatement object.
175  
176  
177 =head2 C<parse>
178  
179 =over 4
180  
181 =item * C<< $if->parse( integer index into array, array of sqlfragments ) >>
182  
183 This is the method which parses the split up SQL code.
184
185 =back
186  
187  
188 =head2 C<condition>
189  
190 =over 4
191  
192 =item * C<< $if->condition() >>
193  
194 TSQL::AST::SQLConditionalExpression representing the condition clause of the While statement.
195
196 =back
197  
198  
199 =head2 C<ifBranch>
200  
201 =over 4
202  
203 =item * C<< $if->ifBranch() >>
204  
205 TSQL::AST::SQLStatement representing the body of the If statement if-branch.
206
207 =back
208  
209  
210 =head2 C<elseBranch>
211  
212 =over 4
213  
214 =item * C<< $if->elseBranch() >>
215  
216 Optional TSQL::AST::SQLStatement representing the body of the If statement optional else-branch.
217
218 =back
219  
220  
221 =head1 LIMITATIONS
222  
223 No limitations are currently known, as far as the intended usage is concerned.
224 You *are* bound to uncover a large number of problems.
225  
226 Please report any problematic cases.
227  
228  
229 =head1 SUPPORT
230  
231 You can find documentation for this module with the perldoc command.
232  
233 perldoc TSQL::AST::SQLIfStatement
234  
235  
236 You can also look for information at:
237  
238 =over 4
239  
240 =item * RT: CPAN's request tracker (report bugs here)
241  
242 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=TSQL::AST>
243  
244 =item * AnnoCPAN: Annotated CPAN documentation
245  
246 L<http://annocpan.org/dist/TSQL::AST>
247  
248 =item * CPAN Ratings
249  
250 L<http://cpanratings.perl.org/d/TSQL::AST>
251  
252 =item * Search CPAN
253  
254 L<http://search.cpan.org/dist/TSQL::AST/>
255  
256 =back
257  
258  
259 =head1 ACKNOWLEDGEMENTS
260  
261 =over 4
262  
263 None yet.
264  
265 =back
266  
267  
268 =head1 SEE ALSO
269  
270  
271 =head1 LICENSE AND COPYRIGHT
272  
273 Copyright 2012 Ded MedVed.
274  
275 This program is free software; you can redistribute it and/or modify it
276 under the terms of either: the GNU General Public License as published
277 by the Free Software Foundation; or the Artistic License.
278  
279 See http://dev.perl.org/licenses/ for more information.
280  
281  
282 =cut
283  
284 4 1; # End of TSQL::AST::SQLIfStatement
285  
286  
287  
↑ Summary lib/TSQL/AST/SQLTryCatchBlock.pm »