line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VoiceXML::Client::Item::Form; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
18
|
use base qw (VoiceXML::Client::Item); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1650
|
|
4
|
3
|
|
|
3
|
|
23
|
use VoiceXML::Client::Util; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
80
|
|
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 . |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
92
|
|
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
6326
|
use vars qw{ |
47
|
|
|
|
|
|
|
$VERSION |
48
|
3
|
|
|
3
|
|
16
|
}; |
|
3
|
|
|
|
|
6
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$VERSION = $VoiceXML::Client::Item::VERSION; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub init { |
56
|
7
|
|
|
7
|
1
|
13
|
my $self = shift; |
57
|
7
|
|
|
|
|
15
|
my $params = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
7
|
|
|
|
|
14
|
$self->{'grammars'} = {}; |
62
|
7
|
50
|
|
|
|
24
|
unless (defined $self->{'id'}) |
63
|
|
|
|
|
|
|
{ |
64
|
7
|
|
66
|
|
|
33
|
$self->id($self->{'XMLElement'}->attribute('id') || int(rand(999999)) . time()); |
65
|
|
|
|
|
|
|
|
66
|
7
|
|
|
|
|
18
|
$self->{'formVar'} = "formVar_" . $self->id(); |
67
|
7
|
|
|
|
|
59
|
my $expr = $self->{'XMLElement'}->attribute('expr'); |
68
|
7
|
|
|
|
|
108
|
my $cond = $self->{'XMLElement'}->attribute('cond'); |
69
|
|
|
|
|
|
|
|
70
|
7
|
50
|
33
|
|
|
114
|
if ($expr || $cond) |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
0
|
0
|
|
|
0
|
if ($expr && $cond) |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
|
|
0
|
$self->{'guard'} = "$expr && $cond"; |
75
|
|
|
|
|
|
|
} else { |
76
|
0
|
|
0
|
|
|
0
|
$self->{'guard'} = $expr || $cond; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} else { |
79
|
7
|
|
|
|
|
23
|
$self->{'guard'} = $self->{'formVar'}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
7
|
|
|
|
|
36
|
my $vxmlDoc = $self->getParentVXMLDocument(); |
84
|
7
|
|
|
|
|
21
|
$vxmlDoc->registerForm($self->id(), $self->{'guard'}); |
85
|
7
|
50
|
|
|
|
60
|
VoiceXML::Client::Item::Util->declareVariable($self,$self->{'formVar'}) if ($self->{'formVar'}); |
86
|
|
|
|
|
|
|
|
87
|
7
|
|
|
|
|
25
|
$self->promptCount(0); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
7
|
|
|
|
|
18
|
return 1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub id { |
95
|
25
|
|
|
25
|
0
|
167
|
my $self = shift; |
96
|
25
|
|
|
|
|
40
|
my $setTo = shift; # opptional |
97
|
|
|
|
|
|
|
|
98
|
25
|
100
|
|
|
|
59
|
if (defined $setTo) |
99
|
|
|
|
|
|
|
{ |
100
|
7
|
|
|
|
|
19
|
$self->{'id'} = $setTo; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
25
|
|
|
|
|
90
|
return $self->{'id'}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub enterSub { |
107
|
1
|
|
|
1
|
0
|
1
|
my $self = shift; |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
4
|
my $vxmlDoc = $self->getParentVXMLDocument(); |
110
|
1
|
|
|
|
|
3
|
$self->{'assub'} = 1; |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
4
|
$vxmlDoc->pushPositionStack(); |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
4
|
$self->reset(); |
115
|
1
|
|
|
|
|
3
|
$self->promptCount(0); |
116
|
|
|
|
|
|
|
# $self->enterForm(); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub returnSub { |
120
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#my $vxmlDoc = $self->getParentVXMLDocument(); |
123
|
|
|
|
|
|
|
#$vxmlDoc->popPositionStack(); |
124
|
0
|
|
|
|
|
0
|
$self->{'assub'} = 0; |
125
|
0
|
|
|
|
|
0
|
$self->clearAutoGuard(); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub calledAsSub { |
129
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
130
|
|
|
|
|
|
|
|
131
|
1
|
50
|
33
|
|
|
20
|
return 1 if (exists $self->{'assub'} && $self->{'assub'}); |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
return 0; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub enterForm { |
137
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
0
|
$self->reset(); |
140
|
0
|
|
|
|
|
0
|
$self->promptCount(0); |
141
|
0
|
|
|
|
|
0
|
$self->setAutoGuard(); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub setAutoGuard { |
145
|
6
|
|
|
6
|
0
|
10
|
my $self = shift; |
146
|
|
|
|
|
|
|
|
147
|
6
|
|
|
|
|
19
|
$self->getParentVXMLDocument()->globalVar($self->{'formVar'}, 1); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub clearAutoGuard { |
152
|
4
|
|
|
4
|
0
|
8
|
my $self = shift; |
153
|
|
|
|
|
|
|
|
154
|
4
|
|
|
|
|
12
|
$self->getParentVXMLDocument()->clearGlobalVar($self->{'formVar'}); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub reset { |
160
|
3
|
|
|
3
|
0
|
5
|
my $self = shift; |
161
|
|
|
|
|
|
|
|
162
|
3
|
50
|
|
|
|
11
|
VoiceXML::Client::Util::log_msg("FORM $self->{'id'} reset() called") if ($VoiceXML::Client::Debug > 1); |
163
|
|
|
|
|
|
|
|
164
|
3
|
|
|
|
|
10
|
$self->clearAutoGuard(); |
165
|
3
|
|
|
|
|
10
|
$self->promptCount(0); |
166
|
|
|
|
|
|
|
|
167
|
3
|
|
|
|
|
21
|
$self->SUPER::reset(0); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub nextItem { |
171
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
172
|
|
|
|
|
|
|
|
173
|
1
|
50
|
|
|
|
4
|
VoiceXML::Client::Util::log_msg("Form::nextItem not implemented yet") if ($VoiceXML::Client::Debug); |
174
|
|
|
|
|
|
|
|
175
|
1
|
|
|
|
|
4
|
return 0; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub execute { |
180
|
6
|
|
|
6
|
0
|
12
|
my $self = shift; |
181
|
6
|
|
|
|
|
9
|
my $handle = shift; |
182
|
6
|
|
|
|
|
9
|
my $optParms = shift; |
183
|
|
|
|
|
|
|
|
184
|
6
|
50
|
|
|
|
16
|
VoiceXML::Client::Util::log_msg("Entering form " . $self->id()) if ($VoiceXML::Client::Debug); |
185
|
|
|
|
|
|
|
|
186
|
6
|
|
|
|
|
19
|
$self->incrementPromptCount(); |
187
|
|
|
|
|
|
|
|
188
|
6
|
50
|
|
|
|
13
|
if ($self->promptCount() > 10) |
189
|
|
|
|
|
|
|
{ |
190
|
0
|
|
|
|
|
0
|
VoiceXML::Client::Util::log_msg("This form (" . $self->{'id'} . ") tried too often... aborting"); |
191
|
0
|
|
|
|
|
0
|
return $VoiceXML::Client::Flow::Directive{'ABORT'}; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
6
|
|
|
|
|
43
|
$self->setAutoGuard(); |
195
|
|
|
|
|
|
|
|
196
|
6
|
|
|
|
|
36
|
return $self->executeChildren($handle, $optParms); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub incrementPromptCount { |
201
|
6
|
|
|
6
|
0
|
9
|
my $self = shift; |
202
|
|
|
|
|
|
|
|
203
|
6
|
|
|
|
|
15
|
my $pc = $self->promptCount(); |
204
|
6
|
|
|
|
|
8
|
$pc++; |
205
|
6
|
|
|
|
|
16
|
$self->promptCount($pc); |
206
|
|
|
|
|
|
|
|
207
|
6
|
|
|
|
|
9
|
return $pc; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub promptCount { |
212
|
29
|
|
|
29
|
0
|
37
|
my $self = shift; |
213
|
29
|
|
|
|
|
36
|
my $setTo = shift; |
214
|
|
|
|
|
|
|
|
215
|
29
|
100
|
|
|
|
62
|
if (defined $setTo) |
216
|
|
|
|
|
|
|
{ |
217
|
17
|
|
|
|
|
39
|
$self->{'promptCount'} = $setTo; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
29
|
|
|
|
|
63
|
return $self->{'promptCount'}; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub inputValidAccordingToGrammar { |
225
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
226
|
0
|
|
0
|
|
|
|
my $input = shift || ''; |
227
|
0
|
|
|
|
|
|
my $gramID = shift; # optional |
228
|
|
|
|
|
|
|
|
229
|
0
|
0
|
|
|
|
|
if ($gramID) |
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'}}) |
|
0
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
{ |
238
|
0
|
0
|
|
|
|
|
return 1 if ($grammar->isValidInput($input)); |
239
|
0
|
|
|
|
|
|
$gramCount++; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
0
|
0
|
|
|
|
|
return 0 if ($gramCount); # failed all grammars... |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
# no grammars set... always good! |
245
|
0
|
|
|
|
|
|
return 1; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub registerGrammar { |
250
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
251
|
0
|
|
|
|
|
|
my $id = shift; |
252
|
0
|
|
0
|
|
|
|
my $grammar = shift || return; |
253
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
$self->{'grammars'}->{$id} = $grammar; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub isaFormItem { |
260
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
261
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
return 1; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
1; |