| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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 . |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
3
|
|
|
3
|
|
18
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
97
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
5905
|
use vars qw{ |
|
43
|
|
|
|
|
|
|
$VERSION |
|
44
|
3
|
|
|
3
|
|
16
|
}; |
|
|
3
|
|
|
|
|
5
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$VERSION = $VoiceXML::Client::VERSION; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub declareVariable { |
|
49
|
14
|
|
|
14
|
0
|
20
|
my $class = shift; |
|
50
|
14
|
|
|
|
|
18
|
my $item = shift; |
|
51
|
14
|
|
50
|
|
|
40
|
my $name = shift || return; |
|
52
|
14
|
|
66
|
|
|
58
|
my $vxmlDoc = shift || $item->getParentVXMLDocument(); |
|
53
|
|
|
|
|
|
|
|
|
54
|
14
|
|
|
|
|
47
|
return $vxmlDoc->registerVariable($name); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub resetVariable { |
|
59
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
|
60
|
0
|
|
|
|
|
0
|
my $item = shift; |
|
61
|
0
|
|
0
|
|
|
0
|
my $name = shift || return; |
|
62
|
0
|
|
0
|
|
|
0
|
my $vxmlDoc = shift || $item->getParentVXMLDocument(); |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
return $vxmlDoc->clearGlobalVar($name); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub assignVariable { |
|
69
|
5
|
|
|
5
|
0
|
8
|
my $class = shift; |
|
70
|
5
|
|
|
|
|
7
|
my $item = shift; |
|
71
|
5
|
|
50
|
|
|
15
|
my $name = shift || return; |
|
72
|
5
|
|
|
|
|
9
|
my $expr = shift ; |
|
73
|
5
|
|
66
|
|
|
22
|
my $vxmlDoc = shift || $item->getParentVXMLDocument(); |
|
74
|
|
|
|
|
|
|
|
|
75
|
5
|
|
|
|
|
9
|
my $varVal; |
|
76
|
5
|
50
|
33
|
|
|
38
|
if (defined $expr && length($expr)) |
|
77
|
|
|
|
|
|
|
{ |
|
78
|
5
|
|
|
|
|
17
|
$varVal = $class->evaluateExpression($item, $expr, $vxmlDoc); |
|
79
|
|
|
|
|
|
|
} else { |
|
80
|
0
|
|
|
|
|
0
|
$varVal = ''; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
5
|
|
|
|
|
20
|
$vxmlDoc->globalVar($name, $varVal); |
|
84
|
|
|
|
|
|
|
|
|
85
|
5
|
|
|
|
|
13
|
return $varVal; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub evaluateExpression { |
|
89
|
5
|
|
|
5
|
0
|
14
|
my $class = shift; |
|
90
|
5
|
|
|
|
|
14
|
my $item = shift; |
|
91
|
5
|
|
|
|
|
10
|
my $expr = shift ; |
|
92
|
5
|
|
33
|
|
|
14
|
my $vxmlDoc = shift || $item->getParentVXMLDocument(); |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
5
|
|
|
|
|
5
|
my $varVal; |
|
96
|
|
|
|
|
|
|
|
|
97
|
5
|
50
|
33
|
|
|
25
|
if (defined $expr && length($expr)) |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
5
|
50
|
|
|
|
15
|
if ($expr =~ m/^\s*'(.+)'\s*$/) |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
0
|
|
|
|
|
0
|
$varVal = $1; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} else { |
|
104
|
|
|
|
|
|
|
|
|
105
|
5
|
|
|
|
|
22
|
$varVal = $class->doEval($expr, $vxmlDoc); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} else { |
|
109
|
0
|
0
|
|
|
|
0
|
VoiceXML::Client::Util::log_msg("evaluateExpression() EXPR IS EMPTY") if ($VoiceXML::Client::Debug > 2); |
|
110
|
0
|
|
|
|
|
0
|
$varVal = ''; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
5
|
|
|
|
|
18
|
return $varVal; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub evaluateCondition { |
|
117
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
|
118
|
0
|
|
|
|
|
0
|
my $item = shift; |
|
119
|
0
|
|
0
|
|
|
0
|
my $condition = shift || ''; |
|
120
|
0
|
|
0
|
|
|
0
|
my $vxmlDoc = shift || $item->getParentVXMLDocument(); |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
0
|
return 0 unless ($condition); |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
0
|
$condition =~s/\>/>/smg; |
|
125
|
0
|
|
|
|
|
0
|
$condition =~s/\</
|
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
0
|
$condition =~s/==\s*'/eq '/smg; |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
0
|
my $evRet = $class->doEval($condition, $vxmlDoc) ; |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
0
|
VoiceXML::Client::Util::log_msg("CONDITION EVALUATED TO " . ($evRet ? 'TRUE' : 'FALSE')) if ($VoiceXML::Client::Debug > 1); |
|
|
|
0
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
0
|
return $evRet ? 1 : 0; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub doEval { |
|
138
|
5
|
|
|
5
|
0
|
10
|
my $class = shift; |
|
139
|
5
|
|
|
|
|
8
|
my $code = shift; |
|
140
|
5
|
|
50
|
|
|
16
|
my $vxmlDoc = shift || return; |
|
141
|
|
|
|
|
|
|
|
|
142
|
5
|
50
|
|
|
|
16
|
VoiceXML::Client::Util::log_msg("CHECKING $code") if ($VoiceXML::Client::Debug > 1); |
|
143
|
5
|
50
|
|
|
|
26
|
if ($code !~ m/^\s*(['\w\d_\.\/-]+)(.*)/) |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
0
|
|
|
|
|
0
|
warn "weird condition '$code'"; |
|
146
|
0
|
|
|
|
|
0
|
return undef; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
5
|
100
|
|
|
|
27
|
if ($code =~ m/^\s*-?\d+(\.\d+)?$/) |
|
150
|
|
|
|
|
|
|
{ |
|
151
|
2
|
|
|
|
|
8
|
return $code; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
|
156
|
3
|
|
|
|
|
10
|
my $vname = $1; |
|
157
|
3
|
|
100
|
|
|
16
|
my $rest = $2 || ''; |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
|
160
|
3
|
|
|
|
|
12
|
my $val = $vxmlDoc->globalVar($1); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
|
163
|
3
|
100
|
66
|
|
|
29
|
unless (defined $rest && length($rest)) |
|
164
|
|
|
|
|
|
|
{ |
|
165
|
2
|
50
|
|
|
|
6
|
if ($VoiceXML::Client::Debug) |
|
166
|
|
|
|
|
|
|
{ |
|
167
|
0
|
0
|
|
|
|
0
|
my $valOutputStr = (defined $val) ? $val : ''; |
|
168
|
0
|
|
|
|
|
0
|
VoiceXML::Client::Util::log_msg("EVAL Returning '$valOutputStr'") ; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
2
|
|
|
|
|
5
|
return $val ; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
|
174
|
1
|
|
|
|
|
3
|
my $expr; |
|
175
|
1
|
50
|
|
|
|
3
|
if (defined $val) |
|
176
|
|
|
|
|
|
|
{ |
|
177
|
1
|
50
|
|
|
|
12
|
if ($val =~ m/\w/) |
|
178
|
|
|
|
|
|
|
{ |
|
179
|
1
|
|
|
|
|
5
|
$expr = "'$val'$rest"; |
|
180
|
|
|
|
|
|
|
} else { |
|
181
|
0
|
0
|
|
|
|
0
|
if (length($val)) |
|
182
|
|
|
|
|
|
|
{ |
|
183
|
0
|
|
|
|
|
0
|
$expr = $val . $rest; |
|
184
|
|
|
|
|
|
|
} else { |
|
185
|
0
|
|
|
|
|
0
|
$expr = "0" . $rest; |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
} else { |
|
189
|
0
|
0
|
|
|
|
0
|
if ($rest =~ m/\w/) |
|
190
|
|
|
|
|
|
|
{ |
|
191
|
0
|
|
|
|
|
0
|
$expr = "''" . $rest; |
|
192
|
|
|
|
|
|
|
} else { |
|
193
|
0
|
|
|
|
|
0
|
$expr = "0" . $rest; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
|
198
|
1
|
50
|
|
|
|
4
|
VoiceXML::Client::Util::log_msg("EVALING '$expr'") if ($VoiceXML::Client::Debug > 1); |
|
199
|
1
|
|
|
|
|
83
|
my $retVal = eval $expr; |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
|
202
|
1
|
50
|
|
|
|
6
|
if ($@) |
|
203
|
|
|
|
|
|
|
{ |
|
204
|
0
|
|
|
|
|
0
|
warn $@; |
|
205
|
0
|
|
|
|
|
0
|
return undef; |
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
|
|
208
|
1
|
|
|
|
|
4
|
return $retVal; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |