Client/Item/Form.pm

filter: Statementstmt 69.9% 72 / 103 Branchbran 40.0% 12 / 30 Conditioncond 21.0% 4 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 75.0% 15 / 20 Podpod 6.2% 1 / 16 totaltotal 52.0% 104 / 200 CC 23 SCAR 24.0
CC
23
Cov
58%
inputValidAccordingToGrammar
42.0
init
16.3
registerGrammar
6.0
CRAP 11.0
« Client/Document.pm ↑ Summary Client/Item/Break.pm »
1 package VoiceXML::Client::Item::Form;
2  
3 3 ▶use base qw (VoiceXML::Client::Item);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use VoiceXML::Client::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 =head1 COPYRIGHT AND LICENSE
8  
9
10 Copyright (C) 2007,2008 by Pat Deegan.
11 All rights reserved
12 http://voicexml.psychogenic.com
13  
14 This library is released under the terms of the GNU GPL version 3, making it available only for
15 free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details).
16 Anyone wishing to use this library within a proprietary or otherwise non-GPLed program MUST contact psychogenic.com to
17 acquire a distinct license for their application. This approach encourages the use of free software
18 while allowing for proprietary solutions that support further development.
19  
20  
21 This file is part of VoiceXML::Client.
22  
23
24
25 VoiceXML::Client is free software: you can redistribute it and/or modify
26 it under the terms of the GNU General Public License as published by
27 the Free Software Foundation, either version 3 of the License, or
28 (at your option) any later version.
29  
30 VoiceXML::Client is distributed in the hope that it will be useful,
31 but WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 GNU General Public License for more details.
34  
35 You should have received a copy of the GNU General Public License
36 along with VoiceXML::Client. If not, see <http://www.gnu.org/licenses/>.
37  
38  
39 =cut
40  
41  
42  
43  
44 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 3 ▶use vars qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
47 $VERSION
48 3 };
49  
50 3 $VERSION = $VoiceXML::Client::Item::VERSION;
51  
52  
53  
54  
55 7 ▶sub init {
Subroutine init: called CC=9 SCAR=27.9
Pod documented
56 7 my $self = shift;
57 7 my $params = shift;
58  
59
60
61 7 $self->{'grammars'} = {};
62 7 ▶ unless (defined $self->{'id'})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"id"}) 7 0 7
63 {
64 7 ▶ $self->id($self->{'XMLElement'}->attribute('id') || int(rand(999999)) . time());
Condition66%2/3
$self->{'XMLElement'}->attribute('id') || int(rand 999999) . time
l!l&&r!l&&!r
610
MC/DC0%0/2
$self->{'XMLElement'}->attribute('id') || int(rand 999999) . time
$self->{'XMLElement'}->attribute('id') int(rand 999999) . time
Truth table66%2/3
A || B
A= $self->{'XMLElement'}->attribute('id')B= int(rand 999999) . time
ABresult
1X1
011
000
65
66 7 $self->{'formVar'} = "formVar_" . $self->id();
67 7 my $expr = $self->{'XMLElement'}->attribute('expr');
68 7 my $cond = $self->{'XMLElement'}->attribute('cond');
69
70 7 ▶ if ($expr || $cond)
Branch: 1 branch
BranchTrueFalseTotal
if ($expr or $cond) { } 0 7 7
Condition33%1/3
$expr or $cond
l!l&&r!l&&!r
007
MC/DC0%0/2
$expr or $cond
$expr $cond
Truth table33%1/3
A or B
A= $exprB= $cond
ABresult
1X1
011
000
71 {
72 0 ▶ if ($expr && $cond)
Branch: 1 branch
BranchTrueFalseTotal
if ($expr and $cond) { } 0 0 0
Condition0%0/3
$expr and $cond
!ll&&!rl&&r
000
MC/DC0%0/2
$expr and $cond
$expr $cond
Truth table0%0/3
A and B
A= $exprB= $cond
ABresult
0X0
100
111
73 {
74 0 $self->{'guard'} = "$expr && $cond";
75 } else {
76 0 ▶ $self->{'guard'} = $expr || $cond;
Condition0%0/3
$expr || $cond
l!l&&r!l&&!r
000
MC/DC0%0/2
$expr || $cond
$expr $cond
Truth table0%0/3
A || B
A= $exprB= $cond
ABresult
1X1
011
000
77 }
78 } else {
79 7 $self->{'guard'} = $self->{'formVar'};
80 }
81
82 }
83 7 my $vxmlDoc = $self->getParentVXMLDocument();
84 7 $vxmlDoc->registerForm($self->id(), $self->{'guard'});
85 7 ▶ VoiceXML::Client::Item::Util->declareVariable($self,$self->{'formVar'}) if ($self->{'formVar'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"formVar"} 7 0 7
86
87 7 $self->promptCount(0);
88
89
90 7 return 1;
91
92 }
93  
94 25 ▶sub id {
Subroutine id: called CC=2 SCAR=6.9
Pod undocumented
95 25 my $self = shift;
96 25 my $setTo = shift; # opptional
97
98 25 ▶ if (defined $setTo)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $setTo) 7 18 25
99 {
100 7 $self->{'id'} = $setTo;
101 }
102
103 25 return $self->{'id'};
104 }
105  
106 1 ▶sub enterSub {
Subroutine enterSub: called CC=1 SCAR=0.0
Pod undocumented
107 1 my $self = shift;
108
109 1 my $vxmlDoc = $self->getParentVXMLDocument();
110 1 $self->{'assub'} = 1;
111
112 1 $vxmlDoc->pushPositionStack();
113
114 1 $self->reset();
115 1 $self->promptCount(0);
116 # $self->enterForm();
117 }
118  
119 0 ▶sub returnSub {
Subroutine returnSub: not called CC=1 SCAR=6.9
Pod undocumented
120 0 my $self = shift;
121
122 #my $vxmlDoc = $self->getParentVXMLDocument();
123 #$vxmlDoc->popPositionStack();
124 0 $self->{'assub'} = 0;
125 0 $self->clearAutoGuard();
126 }
127  
128 1 ▶sub calledAsSub {
Subroutine calledAsSub: called CC=3 SCAR=14.2
Pod undocumented
129 1 my $self = shift;
130
131 1 ▶ return 1 if (exists $self->{'assub'} && $self->{'assub'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"assub"} and $self->{"assub"} 1 0 1
Condition33%1/3
exists $self->{"assub"} and $self->{"assub"}
!ll&&!rl&&r
001
MC/DC0%0/2
exists $self->{"assub"} and $self->{"assub"}
exists $self->{"assub"} $self->{"assub"}
Truth table33%1/3
A and B
A= exists $self->{"assub"}B= $self->{"assub"}
ABresult
0X0
100
111
132
133 0 return 0;
134 }
135  
136 0 ▶sub enterForm {
Subroutine enterForm: not called CC=1 SCAR=6.9
Pod undocumented
137 0 my $self = shift;
138
139 0 $self->reset();
140 0 $self->promptCount(0);
141 0 $self->setAutoGuard();
142 }
143  
144 6 ▶sub setAutoGuard {
Subroutine setAutoGuard: called CC=1 SCAR=0.0
Pod undocumented
145 6 my $self = shift;
146
147 6 $self->getParentVXMLDocument()->globalVar($self->{'formVar'}, 1);
148  
149 }
150  
151 4 ▶sub clearAutoGuard {
Subroutine clearAutoGuard: called CC=1 SCAR=0.0
Pod undocumented
152 4 my $self = shift;
153
154 4 $self->getParentVXMLDocument()->clearGlobalVar($self->{'formVar'});
155  
156 }
157  
158  
159 3 ▶sub reset {
Subroutine reset: called CC=2 SCAR=7.0
Pod undocumented
160 3 my $self = shift;
161
162 3 ▶ VoiceXML::Client::Util::log_msg("FORM $self->{'id'} reset() called") if ($VoiceXML::Client::Debug > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $VoiceXML::Client::Debug > 1 0 3 3
163
164 3 $self->clearAutoGuard();
165 3 $self->promptCount(0);
166
167 3 $self->SUPER::reset(0);
168 }
169  
170 1 ▶sub nextItem {
Subroutine nextItem: called CC=2 SCAR=7.1
Pod undocumented
171 1 my $self = shift;
172
173 1 ▶ VoiceXML::Client::Util::log_msg("Form::nextItem not implemented yet") if ($VoiceXML::Client::Debug);
Branch: 1 branch
BranchTrueFalseTotal
if $VoiceXML::Client::Debug 0 1 1
174
175 1 return 0;
176 }
177
178  
179 6 ▶sub execute {
Subroutine execute: called CC=3 SCAR=11.7
Pod undocumented
180 6 my $self = shift;
181 6 my $handle = shift;
182 6 my $optParms = shift;
183
184 6 ▶ VoiceXML::Client::Util::log_msg("Entering form " . $self->id()) if ($VoiceXML::Client::Debug);
Branch: 1 branch
BranchTrueFalseTotal
if $VoiceXML::Client::Debug 0 6 6
185
186 6 $self->incrementPromptCount();
187
188 6 ▶ if ($self->promptCount() > 10)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->promptCount > 10) 0 6 6
189 {
190 0 VoiceXML::Client::Util::log_msg("This form (" . $self->{'id'} . ") tried too often... aborting");
191 0 return $VoiceXML::Client::Flow::Directive{'ABORT'};
192 }
193
194 6 $self->setAutoGuard();
195
196 6 return $self->executeChildren($handle, $optParms);
197
198 }
199  
200 6 ▶sub incrementPromptCount {
Subroutine incrementPromptCount: called CC=1 SCAR=0.0
Pod undocumented
201 6 my $self = shift;
202
203 6 my $pc = $self->promptCount();
204 6 $pc++;
205 6 $self->promptCount($pc);
206
207 6 return $pc;
208 }
209  
210  
211 29 ▶sub promptCount {
Subroutine promptCount: called CC=2 SCAR=6.9
Pod undocumented
212 29 my $self = shift;
213 29 my $setTo = shift;
214
215 29 ▶ if (defined $setTo)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $setTo) 17 12 29
216 {
217 17 $self->{'promptCount'} = $setTo;
218 }
219
220 29 return $self->{'promptCount'};
221
222 }
223  
224 0 ▶sub inputValidAccordingToGrammar {
Subroutine inputValidAccordingToGrammar: not called CC=6 SCAR=37.4
Pod undocumented
225 0 my $self = shift;
226 0 ▶ my $input = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
227 0 my $gramID = shift; # optional
228
229 0 ▶ if ($gramID)
Branch: 1 branch
BranchTrueFalseTotal
if ($gramID) 0 0 0
230 {
231 0 return $self->{'grammars'}->{$gramID}->isValidInput($input);
232 }
233
234 # no gramID... try 'em all
235 0 my $gramCount = 0;
236 0 ▶ while (my ($gid, $grammar) = each %{$self->{'grammars'}})
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"grammars"};}) 0 0 0
237 {
238 0 ▶ return 1 if ($grammar->isValidInput($input));
Branch: 1 branch
BranchTrueFalseTotal
if $grammar->isValidInput($input) 0 0 0
239 0 $gramCount++;
240 }
241
242 0 ▶ return 0 if ($gramCount); # failed all grammars...
Branch: 1 branch
BranchTrueFalseTotal
if $gramCount 0 0 0
243
244 # no grammars set... always good!
245 0 return 1;
246 }
247
248  
249 0 ▶sub registerGrammar {
Subroutine registerGrammar: not called CC=2 SCAR=17.9
Pod undocumented
250 0 my $self = shift;
251 0 my $id = shift;
252 0 ▶ my $grammar = 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
253
254 0 $self->{'grammars'}->{$id} = $grammar;
255 }
256  
257  
258  
259 0 ▶sub isaFormItem {
Subroutine isaFormItem: not called CC=1 SCAR=6.9
Pod undocumented
260 0 my $self = shift;
261
262 0 return 1;
263 }
264  
265  
266 3 1;
« Client/Document.pm ↑ Summary Client/Item/Break.pm »