lib/TSQL/AST/Factory.pm

filter: Statementstmt 94.6% 159 / 168 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 22 / 66 MC/DCmcdc 0.0% 0 / 44 Subroutinesub 100% 30 / 30 Podpod 0.0% 0 / 4 totaltotal 67.1% 215 / 320 CC 9 SCAR 5.1
CC
9
Cov
76%
makeStatement
3.2
makeToken
3.1
makeIfStatement
3.1
CRAP 1.7
« script/parsetsql.pl ↑ Summary lib/TSQL/AST/SQLScript.pm »
1 package TSQL::AST::Factory;
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3
4 4 ▶use feature "switch";
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 4 ▶use TSQL::AST::Token::Begin;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use TSQL::AST::Token::BeginCatch;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use TSQL::AST::Token::BeginTry;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use TSQL::AST::Token::Else;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use TSQL::AST::Token::End;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use TSQL::AST::Token::EndCatch;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use TSQL::AST::Token::EndTry;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use TSQL::AST::Token::GO;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use TSQL::AST::Token::If;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use TSQL::AST::Token::While;
Subroutine BEGIN: called CC=1 SCAR=0.0
17
18 4 ▶use TSQL::AST::SQLFragment;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use TSQL::AST::SQLConditionalExpression;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use TSQL::AST::SQLIfStatement;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use TSQL::AST::SQLTryCatchBlock;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use TSQL::AST::SQLWhileStatement;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use TSQL::AST::SQLStatement;
Subroutine BEGIN: called CC=1 SCAR=0.0
24
25 4 ▶use TSQL::AST::Token::CreateOrAlterFunction;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use TSQL::AST::Token::CreateOrAlterProcedure;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use TSQL::AST::Token::CreateOrAlterTrigger;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use TSQL::AST::Token::CreateOrAlterView;
Subroutine BEGIN: called CC=1 SCAR=0.0
29
30
31 4 ▶use TSQL::Common::Regexp;
Subroutine BEGIN: called CC=1 SCAR=0.0
32
33 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
35
36 =head1 NAME
37
38 TSQL::AST::Factory - Builds various parsing objects.
39
40 =head1 VERSION
41
42 Version 0.03
43
44 =cut
45
46
47 #our \$VERSION = '0.03';
48
49 4 ▶my $qr_begintoken //= TSQL::Common::Regexp->qr_begintoken();
Condition33%1/3
my $qr_begintoken //= "TSQL::Common::Regexp"->qr_begintoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_begintoken //= "TSQL::Common::Regexp"->qr_begintoken
my $qr_begintoken "TSQL::Common::Regexp"->qr_begintoken
Truth table33%1/3
A //= B
A= my $qr_begintokenB= "TSQL::Common::Regexp"->qr_begintoken
ABresult
1X1
011
000
50 4 ▶my $qr_endtoken //= TSQL::Common::Regexp->qr_endtoken();
Condition33%1/3
my $qr_endtoken //= "TSQL::Common::Regexp"->qr_endtoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_endtoken //= "TSQL::Common::Regexp"->qr_endtoken
my $qr_endtoken "TSQL::Common::Regexp"->qr_endtoken
Truth table33%1/3
A //= B
A= my $qr_endtokenB= "TSQL::Common::Regexp"->qr_endtoken
ABresult
1X1
011
000
51 4 ▶my $qr_begintrytoken //= TSQL::Common::Regexp->qr_begintrytoken();
Condition33%1/3
my $qr_begintrytoken //= "TSQL::Common::Regexp"->qr_begintrytoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_begintrytoken //= "TSQL::Common::Regexp"->qr_begintrytoken
my $qr_begintrytoken "TSQL::Common::Regexp"->qr_begintrytoken
Truth table33%1/3
A //= B
A= my $qr_begintrytokenB= "TSQL::Common::Regexp"->qr_begintrytoken
ABresult
1X1
011
000
52 4 ▶my $qr_endtrytoken //= TSQL::Common::Regexp->qr_endtrytoken();
Condition33%1/3
my $qr_endtrytoken //= "TSQL::Common::Regexp"->qr_endtrytoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_endtrytoken //= "TSQL::Common::Regexp"->qr_endtrytoken
my $qr_endtrytoken "TSQL::Common::Regexp"->qr_endtrytoken
Truth table33%1/3
A //= B
A= my $qr_endtrytokenB= "TSQL::Common::Regexp"->qr_endtrytoken
ABresult
1X1
011
000
53 4 ▶my $qr_begincatchtoken //= TSQL::Common::Regexp->qr_begincatchtoken();
Condition33%1/3
my $qr_begincatchtoken //= "TSQL::Common::Regexp"->qr_begincatchtoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_begincatchtoken //= "TSQL::Common::Regexp"->qr_begincatchtoken
my $qr_begincatchtoken "TSQL::Common::Regexp"->qr_begincatchtoken
Truth table33%1/3
A //= B
A= my $qr_begincatchtokenB= "TSQL::Common::Regexp"->qr_begincatchtoken
ABresult
1X1
011
000
54 4 ▶my $qr_endcatchtoken //= TSQL::Common::Regexp->qr_endcatchtoken();
Condition33%1/3
my $qr_endcatchtoken //= "TSQL::Common::Regexp"->qr_endcatchtoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_endcatchtoken //= "TSQL::Common::Regexp"->qr_endcatchtoken
my $qr_endcatchtoken "TSQL::Common::Regexp"->qr_endcatchtoken
Truth table33%1/3
A //= B
A= my $qr_endcatchtokenB= "TSQL::Common::Regexp"->qr_endcatchtoken
ABresult
1X1
011
000
55 4 ▶my $qr_iftoken //= TSQL::Common::Regexp->qr_iftoken();
Condition33%1/3
my $qr_iftoken //= "TSQL::Common::Regexp"->qr_iftoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_iftoken //= "TSQL::Common::Regexp"->qr_iftoken
my $qr_iftoken "TSQL::Common::Regexp"->qr_iftoken
Truth table33%1/3
A //= B
A= my $qr_iftokenB= "TSQL::Common::Regexp"->qr_iftoken
ABresult
1X1
011
000
56 4 ▶my $qr_elsetoken //= TSQL::Common::Regexp->qr_elsetoken();
Condition33%1/3
my $qr_elsetoken //= "TSQL::Common::Regexp"->qr_elsetoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_elsetoken //= "TSQL::Common::Regexp"->qr_elsetoken
my $qr_elsetoken "TSQL::Common::Regexp"->qr_elsetoken
Truth table33%1/3
A //= B
A= my $qr_elsetokenB= "TSQL::Common::Regexp"->qr_elsetoken
ABresult
1X1
011
000
57 4 ▶my $qr_whiletoken //= TSQL::Common::Regexp->qr_whiletoken();
Condition33%1/3
my $qr_whiletoken //= "TSQL::Common::Regexp"->qr_whiletoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_whiletoken //= "TSQL::Common::Regexp"->qr_whiletoken
my $qr_whiletoken "TSQL::Common::Regexp"->qr_whiletoken
Truth table33%1/3
A //= B
A= my $qr_whiletokenB= "TSQL::Common::Regexp"->qr_whiletoken
ABresult
1X1
011
000
58 4 ▶my $qr_GOtoken //= TSQL::Common::Regexp->qr_GOtoken();
Condition33%1/3
my $qr_GOtoken //= "TSQL::Common::Regexp"->qr_GOtoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_GOtoken //= "TSQL::Common::Regexp"->qr_GOtoken
my $qr_GOtoken "TSQL::Common::Regexp"->qr_GOtoken
Truth table33%1/3
A //= B
A= my $qr_GOtokenB= "TSQL::Common::Regexp"->qr_GOtoken
ABresult
1X1
011
000
59
60
61 4 ▶my $qr_createproceduretoken //= TSQL::Common::Regexp->qr_createproceduretoken();
Condition33%1/3
my $qr_createproceduretoken //= "TSQL::Common::Regexp"->qr_createproceduretoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_createproceduretoken //= "TSQL::Common::Regexp"->qr_createproceduretoken
my $qr_createproceduretoken "TSQL::Common::Regexp"->qr_createproceduretoken
Truth table33%1/3
A //= B
A= my $qr_createproceduretokenB= "TSQL::Common::Regexp"->qr_createproceduretoken
ABresult
1X1
011
000
62 4 ▶my $qr_alterproceduretoken //= TSQL::Common::Regexp->qr_alterproceduretoken();
Condition33%1/3
my $qr_alterproceduretoken //= "TSQL::Common::Regexp"->qr_alterproceduretoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_alterproceduretoken //= "TSQL::Common::Regexp"->qr_alterproceduretoken
my $qr_alterproceduretoken "TSQL::Common::Regexp"->qr_alterproceduretoken
Truth table33%1/3
A //= B
A= my $qr_alterproceduretokenB= "TSQL::Common::Regexp"->qr_alterproceduretoken
ABresult
1X1
011
000
63 4 ▶my $qr_createtriggertoken //= TSQL::Common::Regexp->qr_createtriggertoken();
Condition33%1/3
my $qr_createtriggertoken //= "TSQL::Common::Regexp"->qr_createtriggertoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_createtriggertoken //= "TSQL::Common::Regexp"->qr_createtriggertoken
my $qr_createtriggertoken "TSQL::Common::Regexp"->qr_createtriggertoken
Truth table33%1/3
A //= B
A= my $qr_createtriggertokenB= "TSQL::Common::Regexp"->qr_createtriggertoken
ABresult
1X1
011
000
64 4 ▶my $qr_altertriggertoken //= TSQL::Common::Regexp->qr_altertriggertoken();
Condition33%1/3
my $qr_altertriggertoken //= "TSQL::Common::Regexp"->qr_altertriggertoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_altertriggertoken //= "TSQL::Common::Regexp"->qr_altertriggertoken
my $qr_altertriggertoken "TSQL::Common::Regexp"->qr_altertriggertoken
Truth table33%1/3
A //= B
A= my $qr_altertriggertokenB= "TSQL::Common::Regexp"->qr_altertriggertoken
ABresult
1X1
011
000
65 4 ▶my $qr_createviewtoken //= TSQL::Common::Regexp->qr_createviewtoken();
Condition33%1/3
my $qr_createviewtoken //= "TSQL::Common::Regexp"->qr_createviewtoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_createviewtoken //= "TSQL::Common::Regexp"->qr_createviewtoken
my $qr_createviewtoken "TSQL::Common::Regexp"->qr_createviewtoken
Truth table33%1/3
A //= B
A= my $qr_createviewtokenB= "TSQL::Common::Regexp"->qr_createviewtoken
ABresult
1X1
011
000
66 4 ▶my $qr_alterviewtoken //= TSQL::Common::Regexp->qr_alterviewtoken();
Condition33%1/3
my $qr_alterviewtoken //= "TSQL::Common::Regexp"->qr_alterviewtoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_alterviewtoken //= "TSQL::Common::Regexp"->qr_alterviewtoken
my $qr_alterviewtoken "TSQL::Common::Regexp"->qr_alterviewtoken
Truth table33%1/3
A //= B
A= my $qr_alterviewtokenB= "TSQL::Common::Regexp"->qr_alterviewtoken
ABresult
1X1
011
000
67 4 ▶my $qr_createfunctiontoken //= TSQL::Common::Regexp->qr_createfunctiontoken();
Condition33%1/3
my $qr_createfunctiontoken //= "TSQL::Common::Regexp"->qr_createfunctiontoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_createfunctiontoken //= "TSQL::Common::Regexp"->qr_createfunctiontoken
my $qr_createfunctiontoken "TSQL::Common::Regexp"->qr_createfunctiontoken
Truth table33%1/3
A //= B
A= my $qr_createfunctiontokenB= "TSQL::Common::Regexp"->qr_createfunctiontoken
ABresult
1X1
011
000
68 4 ▶my $qr_alterfunctiontoken //= TSQL::Common::Regexp->qr_alterfunctiontoken();
Condition33%1/3
my $qr_alterfunctiontoken //= "TSQL::Common::Regexp"->qr_alterfunctiontoken
l!l&&r!l&&!r
040
MC/DC0%0/2
my $qr_alterfunctiontoken //= "TSQL::Common::Regexp"->qr_alterfunctiontoken
my $qr_alterfunctiontoken "TSQL::Common::Regexp"->qr_alterfunctiontoken
Truth table33%1/3
A //= B
A= my $qr_alterfunctiontokenB= "TSQL::Common::Regexp"->qr_alterfunctiontoken
ABresult
1X1
011
000
69
70 210 ▶sub makeToken {
Subroutine makeToken: called CC=3 SCAR=11.3
Pod undocumented
71
72 210 local $_ = undef ;
73
74 210 my $invocant = shift ;
75 210 ▶ my $class = ref($invocant) || $invocant ;
Condition33%1/3
ref $invocant || $invocant
l!l&&r!l&&!r
02100
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
76
77 210 my $input = shift ;
78 210 ▶ carp "Missing token input" if ! defined $input;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input 0 210 210
79
80 210 my $o ;
81
82 210 given ($input) {
83
84 when ( m{$qr_begintoken}ix )
85 210 { $o = TSQL::AST::Token::Begin->new( tokenString => $input ) ; }
86
87 when ( m{$qr_endtoken}ix )
88 185 { $o = TSQL::AST::Token::End->new( tokenString => $input ) ; }
89
90 when ( m{$qr_begintrytoken}ix )
91 160 { $o = TSQL::AST::Token::BeginTry->new( tokenString => $input ) ; }
92
93 when ( m{$qr_endtrytoken}ix )
94 146 { $o = TSQL::AST::Token::EndTry->new( tokenString => $input ) ; }
95
96 when ( m{$qr_begincatchtoken}ix )
97 132 { $o = TSQL::AST::Token::BeginCatch->new( tokenString => $input ) ; }
98
99 when ( m{$qr_endcatchtoken}ix )
100 118 { $o = TSQL::AST::Token::EndCatch->new( tokenString => $input ) ; }
101
102 when ( m{$qr_elsetoken}ix )
103 104 { $o = TSQL::AST::Token::Else->new( tokenString => $input ) ; }
104
105 when ( m{$qr_iftoken}ix )
106 97 { $o = TSQL::AST::Token::If->new( tokenString => $input ) ; }
107
108 when ( m{$qr_GOtoken}ix )
109 87 { $o = TSQL::AST::Token::GO->new( tokenString => $input ) ; }
110
111 when ( m{$qr_whiletoken}ix )
112 77 { $o = TSQL::AST::Token::While->new( tokenString => $input ) ; }
113
114
115 when ( m{$qr_createproceduretoken}ix )
116 0 { $o = TSQL::AST::Token::CreateOrAlterProcedure->new( tokenString => $input ) ; }
117
118 when ( m{$qr_alterproceduretoken}ix )
119 0 { $o = TSQL::AST::Token::CreateOrAlterProcedure->new( tokenString => $input ) ; }
120
121 when ( m{$qr_createtriggertoken}ix )
122 0 { $o = TSQL::AST::Token::CreateOrAlterTrigger->new( tokenString => $input ) ; }
123
124 when ( m{$qr_altertriggertoken}ix )
125 0 { $o = TSQL::AST::Token::CreateOrAlterTrigger->new( tokenString => $input ) ; }
126
127 when ( m{$qr_createviewtoken}ix )
128 0 { $o = TSQL::AST::Token::CreateOrAlterView->new( tokenString => $input ) ; }
129
130 when ( m{$qr_alterviewtoken}ix )
131 0 { $o = TSQL::AST::Token::CreateOrAlterView->new( tokenString => $input ) ; }
132
133 when ( m{$qr_createfunctiontoken}ix )
134 0 { $o = TSQL::AST::Token::CreateOrAlterFunction->new( tokenString => $input ) ; }
135
136 when ( m{$qr_alterfunctiontoken}ix )
137 0 { $o = TSQL::AST::Token::CreateOrAlterFunction->new( tokenString => $input ) ; }
138
139 }
140
141 210 return $o;
142 }
143
144 63 ▶sub makeStatement {
Subroutine makeStatement: called CC=3 SCAR=11.5
Pod undocumented
145
146 63 local $_ = undef ;
147
148 63 my $invocant = shift ;
149 63 ▶ my $class = ref($invocant) || $invocant ;
Condition33%1/3
ref $invocant || $invocant
l!l&&r!l&&!r
0630
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
150
151 63 my $input = shift ;
152 63 ▶ carp "Missing statement input" if ! defined $input;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input 0 63 63
153
154 63 my $o ;
155
156 63 given ($input) {
157 # when ( m{\A \s* (?:\b if \b) \s* }xi )
158 # { $o = TSQL::AST::SQLIfStatement->new( tokenString => $input ) ; }
159 # when ( m{\A \s* (?:\b begin \b \s* \b try \b ) \s* \z }xi )
160 # { $o = TSQL::AST::SQLTryCatchBlock->new( tokenString => $input ) ;
161 # }
162 # when ( m{\A \s* (?:\b while \b)}xi )
163 # { $o = TSQL::AST::SQLWhileStatement->new( tokenString => $input ) ; }
164 63 default { $o = TSQL::AST::SQLStatement->new( tokenString => $input ) ;
165 }
166
167 0 return $o;
168 }
169 }
170
171 10 ▶sub makeIfStatement {
Subroutine makeIfStatement: called CC=3 SCAR=11.3
Pod undocumented
172
173 10 local $_ = undef ;
174
175 10 my $invocant = shift ;
176 10 ▶ my $class = ref($invocant) || $invocant ;
Condition33%1/3
ref $invocant || $invocant
l!l&&r!l&&!r
0100
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
177
178 10 my $condition = shift ;
179 10 ▶ carp "Missing statement input" if ! defined $condition;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $condition 0 10 10
180
181 10 $condition =~ s{$qr_iftoken}{}xmis;
182 10 my $fr = TSQL::AST::SQLFragment->new( tokenString => $condition ) ;
183 10 my $co = TSQL::AST::SQLConditionalExpression->new( expression => $fr ) ;
184 10 return TSQL::AST::SQLIfStatement->new( condition => $co ) ;
185
186 }
187
188 12 ▶sub makeWhileStatement {
Subroutine makeWhileStatement: called CC=3 SCAR=11.3
Pod undocumented
189
190 12 local $_ = undef ;
191
192 12 my $invocant = shift ;
193 12 ▶ my $class = ref($invocant) || $invocant ;
Condition33%1/3
ref $invocant || $invocant
l!l&&r!l&&!r
0120
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
194
195 12 my $condition = shift ;
196 12 ▶ carp "Missing statement input" if ! defined $condition;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $condition 0 12 12
197
198 12 $condition =~ s{$qr_whiletoken}{}xmis;
199 12 my $fr = TSQL::AST::SQLFragment->new( tokenString => $condition ) ;
200 12 my $co = TSQL::AST::SQLConditionalExpression->new( expression => $fr ) ;
201 12 return TSQL::AST::SQLWhileStatement->new( condition => $co ) ;
202
203 }
204
205 4 1;
206
207 __DATA__
« script/parsetsql.pl ↑ Summary lib/TSQL/AST/SQLScript.pm »