Client/Item/Util.pm

filter: Statementstmt 62.3% 53 / 85 Branchbran 35.0% 14 / 40 Conditioncond 38.8% 14 / 36 MC/DCmcdc 9.0% 2 / 22 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 6 totaltotal 45.1% 89 / 197 CC 35 SCAR 32.5
CC
35
Cov
50%
evaluateCondition
56.0
doEval
35.2
resetVariable
12.0
CRAP 25.9
« Client/Engine/Component/Interpreter/Perl.pm ↑ Summary Client/Item/Submit.pm »
1 package VoiceXML::Client::Item::Util;
2  
3  
4 =head1 COPYRIGHT AND LICENSE
5  
6
7 Copyright (C) 2007,2008 by Pat Deegan.
8 All rights reserved
9 http://voicexml.psychogenic.com
10  
11 This library is released under the terms of the GNU GPL version 3, making it available only for
12 free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details).
13 Anyone wishing to use this library within a proprietary or otherwise non-GPLed program MUST contact psychogenic.com to
14 acquire a distinct license for their application. This approach encourages the use of free software
15 while allowing for proprietary solutions that support further development.
16  
17  
18 This file is part of VoiceXML::Client.
19  
20
21
22 VoiceXML::Client is free software: you can redistribute it and/or modify
23 it under the terms of the GNU General Public License as published by
24 the Free Software Foundation, either version 3 of the License, or
25 (at your option) any later version.
26  
27 VoiceXML::Client is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31  
32 You should have received a copy of the GNU General Public License
33 along with VoiceXML::Client. If not, see <http://www.gnu.org/licenses/>.
34  
35  
36 =cut
37  
38  
39  
40 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 3 ▶use vars qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
43 $VERSION
44 3 };
45  
46 3 $VERSION = $VoiceXML::Client::VERSION;
47  
48 14 ▶sub declareVariable {
Subroutine declareVariable: called CC=3 SCAR=11.2
Pod undocumented
49 14 my $class = shift;
50 14 my $item = shift;
51 14 ▶ my $name = shift || return;
Condition50%1/2
shift() || (return)
l!l
140
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
52 14 ▶ my $vxmlDoc = shift || $item->getParentVXMLDocument();
Condition66%2/3
shift() || $item->getParentVXMLDocument
l!l&&r!l&&!r
680
MC/DC0%0/2
shift() || $item->getParentVXMLDocument
shift() $item->getParentVXMLDocument
Truth table66%2/3
A || B
A= shift()B= $item->getParentVXMLDocument
ABresult
1X1
011
000
53
54 14 return $vxmlDoc->registerVariable($name);
55 }
56  
57  
58 0 ▶sub resetVariable {
Subroutine resetVariable: not called CC=3 SCAR=24.8
Pod undocumented
59 0 my $class = shift;
60 0 my $item = shift;
61 0 ▶ my $name = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
62 0 ▶ my $vxmlDoc = shift || $item->getParentVXMLDocument();
Condition0%0/3
shift() || $item->getParentVXMLDocument
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $item->getParentVXMLDocument
shift() $item->getParentVXMLDocument
Truth table0%0/3
A || B
A= shift()B= $item->getParentVXMLDocument
ABresult
1X1
011
000
63
64 0 return $vxmlDoc->clearGlobalVar($name);
65 }
66
67  
68 5 ▶sub assignVariable {
Subroutine assignVariable: called CC=5 SCAR=17.2
Pod undocumented
69 5 my $class = shift;
70 5 my $item = shift;
71 5 ▶ my $name = shift || return;
Condition50%1/2
shift() || (return)
l!l
50
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
72 5 my $expr = shift ;
73 5 ▶ my $vxmlDoc = shift || $item->getParentVXMLDocument();
Condition66%2/3
shift() || $item->getParentVXMLDocument
l!l&&r!l&&!r
230
MC/DC0%0/2
shift() || $item->getParentVXMLDocument
shift() $item->getParentVXMLDocument
Truth table66%2/3
A || B
A= shift()B= $item->getParentVXMLDocument
ABresult
1X1
011
000
74
75 5 my $varVal;
76 5 ▶ if (defined $expr && length($expr))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr and length $expr) { } 5 0 5
Condition33%1/3
defined $expr and length $expr
!ll&&!rl&&r
005
MC/DC0%0/2
defined $expr and length $expr
defined $expr length $expr
Truth table33%1/3
A and B
A= defined $exprB= length $expr
ABresult
0X0
100
111
77 {
78 5 $varVal = $class->evaluateExpression($item, $expr, $vxmlDoc);
79 } else {
80 0 $varVal = '';
81 }
82
83 5 $vxmlDoc->globalVar($name, $varVal);
84
85 5 return $varVal;
86 }
87  
88 5 ▶sub evaluateExpression {
Subroutine evaluateExpression: called CC=6 SCAR=22.5
Pod undocumented
89 5 my $class = shift;
90 5 my $item = shift;
91 5 my $expr = shift ;
92 5 ▶ my $vxmlDoc = shift || $item->getParentVXMLDocument();
Condition33%1/3
shift() || $item->getParentVXMLDocument
l!l&&r!l&&!r
500
MC/DC0%0/2
shift() || $item->getParentVXMLDocument
shift() $item->getParentVXMLDocument
Truth table33%1/3
A || B
A= shift()B= $item->getParentVXMLDocument
ABresult
1X1
011
000
93
94
95 5 my $varVal;
96
97 5 ▶ if (defined $expr && length($expr))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr and length $expr) { } 5 0 5
Condition33%1/3
defined $expr and length $expr
!ll&&!rl&&r
005
MC/DC0%0/2
defined $expr and length $expr
defined $expr length $expr
Truth table33%1/3
A and B
A= defined $exprB= length $expr
ABresult
0X0
100
111
98 {
99 5 ▶ if ($expr =~ m/^\s*'(.+)'\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($expr =~ /^\s*'(.+)'\s*$/) { } 0 5 5
100 {
101 0 $varVal = $1;
102
103 } else {
104
105 5 $varVal = $class->doEval($expr, $vxmlDoc);
106 }
107  
108 } else {
109 0 ▶ VoiceXML::Client::Util::log_msg("evaluateExpression() EXPR IS EMPTY") if ($VoiceXML::Client::Debug > 2);
Branch: 1 branch
BranchTrueFalseTotal
if $VoiceXML::Client::Debug > 2 0 0 0
110 0 $varVal = '';
111 }
112
113 5 return $varVal;
114 }
115
116 0 ▶sub evaluateCondition {
Subroutine evaluateCondition: not called CC=7 SCAR=40.3
Pod undocumented
117 0 my $class = shift;
118 0 my $item = shift;
119 0 ▶ my $condition = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
120 0 ▶ my $vxmlDoc = shift || $item->getParentVXMLDocument();
Condition0%0/3
shift() || $item->getParentVXMLDocument
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $item->getParentVXMLDocument
shift() $item->getParentVXMLDocument
Truth table0%0/3
A || B
A= shift()B= $item->getParentVXMLDocument
ABresult
1X1
011
000
121
122 0 ▶ return 0 unless ($condition);
Branch: 1 branch
BranchTrueFalseTotal
unless $condition 0 0 0
123
124 0 $condition =~s/\&gt;/>/smg;
125 0 $condition =~s/\&lt;/</smg;
126
127 0 $condition =~s/==\s*'/eq '/smg;
128
129 0 my $evRet = $class->doEval($condition, $vxmlDoc) ;
130
131 0 ▶ VoiceXML::Client::Util::log_msg("CONDITION EVALUATED TO " . ($evRet ? 'TRUE' : 'FALSE')) if ($VoiceXML::Client::Debug > 1);
Branch: 2 branches
BranchTrueFalseTotal
if $VoiceXML::Client::Debug > 1 0 0 0
$evRet ? : 0 0 0
132 0 ▶ return $evRet ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$evRet ? : 0 0 0
133
134
135 }
136  
137 5 ▶sub doEval {
Subroutine doEval: called CC=16 SCAR=35.6
Pod undocumented
138 5 my $class = shift;
139 5 my $code = shift;
140 5 ▶ my $vxmlDoc = shift || return;
Condition50%1/2
shift() || (return)
l!l
50
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
141
142 5 ▶ VoiceXML::Client::Util::log_msg("CHECKING $code") if ($VoiceXML::Client::Debug > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $VoiceXML::Client::Debug > 1 0 5 5
143 5 ▶ if ($code !~ m/^\s*(['\w\d_\.\/-]+)(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($code =~ m[^\s*(['\w\d_\./-]+)(.*)]) 0 5 5
144 {
145 0 warn "weird condition '$code'";
146 0 return undef;
147 }
148
149 5 ▶ if ($code =~ m/^\s*-?\d+(\.\d+)?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /^\s*-?\d+(\.\d+)?$/) 2 3 5
150 {
151 2 return $code;
152 }
153
154  
155  
156 3 my $vname = $1;
157 3 ▶ my $rest = $2 || '';
Condition100%2/2
$2 || ''
l!l
12
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
158
159
160 3 my $val = $vxmlDoc->globalVar($1);
161
162
163 3 ▶ unless (defined $rest && length($rest))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rest and length $rest) 2 1 3
Condition66%2/3
defined $rest and length $rest
!ll&&!rl&&r
021
MC/DC50%1/2
defined $rest and length $rest
defined $rest length $rest
Truth table66%2/3
A and B
A= defined $restB= length $rest
ABresult
0X0
100
111
164 {
165 2 ▶ if ($VoiceXML::Client::Debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($VoiceXML::Client::Debug) 0 2 2
166 {
167 0 ▶ my $valOutputStr = (defined $val) ? $val : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
168 0 VoiceXML::Client::Util::log_msg("EVAL Returning '$valOutputStr'") ;
169 }
170 2 return $val ;
171 }
172
173
174 1 my $expr;
175 1 ▶ if (defined $val)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 1 0 1
176 {
177 1 ▶ if ($val =~ m/\w/)
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /\w/) { } 1 0 1
178 {
179 1 $expr = "'$val'$rest";
180 } else {
181 0 ▶ if (length($val))
Branch: 1 branch
BranchTrueFalseTotal
if (length $val) { } 0 0 0
182 {
183 0 $expr = $val . $rest;
184 } else {
185 0 $expr = "0" . $rest;
186 }
187 }
188 } else {
189 0 ▶ if ($rest =~ m/\w/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\w/) { } 0 0 0
190 {
191 0 $expr = "''" . $rest;
192 } else {
193 0 $expr = "0" . $rest;
194 }
195 }
196
197
198 1 ▶ VoiceXML::Client::Util::log_msg("EVALING '$expr'") if ($VoiceXML::Client::Debug > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $VoiceXML::Client::Debug > 1 0 1 1
199 1 my $retVal = eval $expr;
200  
201
202 1 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
203 {
204 0 warn $@;
205 0 return undef;
206 }
207
208 1 return $retVal;
209 }
210  
211  
212 3 1;
« Client/Engine/Component/Interpreter/Perl.pm ↑ Summary Client/Item/Submit.pm »