Client.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 90.0% 45 / 50 CC 2 SCAR 6.5
CC
2
Cov
90%
__ANON__
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Client/Item/Assign.pm ↑ Summary Client/Item/NoInput.pm »
1 package VoiceXML::Client;
2  
3  
4  
5 =head1 NAME
6  
7 VoiceXML::Client - Perl extension for VoiceXML (VXML) clients, including useragent, parser and interpreter.
8  
9 =head1 SYNOPSIS
10  
11
12 #!/usr/bin/perl
13
14 use VoiceXML::Client;
15
16 use strict;
17
18 # basic info for VoiceXML source
19 my $sourceSite = 'voicexml.psychogenic.com';
20 my $startURL = '/vocp.cgi';
21
22
23 # using dummy device here, to get started
24 my $telephonyDevice = VoiceXML::Client::Device::Dummy->new();
25 $telephonyDevice->connect();
26
27 # our workhorse: the user agent
28 my $vxmlUserAgent = VoiceXML::Client::UserAgent->new($sourceSite);
29
30 # go for it:
31 $vxmlUserAgent->runApplication($startURL, $telephonyDevice);
32
33 # that's it... runApplication will return when it has hung up the device.
34
35  
36 =head1 DESCRIPTION
37  
38 The VoiceXML::Client library allows you to fetch, parse and interpret VoiceXML files.
39  
40 It was developed as a supporting component of the (upcoming version of the) VOCP voice messaging system (http://www.vocpsystem.com).
41  
42 It's role is to:
43  
44 - fetch vxml files
45 - parse their contents
46 - interpret them by executing the instructions therein
47  
48 It is not (yet) a complete implementation of the VoiceXML specs, but does support a lot of interesting features.
49 Have a look at the included exampleBBSBox.vxml file for an idea of what is possible.
50 A quick tour of this file will give you a taste of what's available.
51  
52  
53 =head2 Telephony Interface
54  
55  
56 As noted above, the user agent's runApplication() method is called with two parameters:
57 a URL and a handle to some telephony device.
58  
59 While executing the voicexml code, VoiceXML::Client will likely need to do things like
60 play audio files, collect user DTMF input and allow callers to leave messages. The vxml
61 page tells VoiceXML::Client what to do, and the telephony interface is used to actually
62 perform these actions.
63  
64 Exactly how the device collects user input etc is left as an excercise to the implementor.
65 The only thing that counts from VoiceXML::Client's perspective is that the handle support
66 the VoiceXML::Client::DeviceHandle interface.
67  
68 During testing, you may use VoiceXML::Client::Device::Dummy as the telephony handle. This
69 is a simplified implementation whose only effect is to print all calls to stdout and
70 request DTMF input from the command line, when required.
71  
72 As a programmer, the majority of your work will be in replacing the VoiceXML::Client::Device::Dummy device in the code above with
73 some implementation of the API that actually controls an interesting device. See the Telephony Interface section on
74  
75
76 http://voicexml.psychogenic.com/api.php
77  
78  
79 for a complete discussion, or have a look at the VoiceXML::Client::Device::Dummy and VoiceXML::Client::DeviceHandle documentation.
80  
81  
82  
83  
84 =head2 VoiceXML
85  
86 A complete discussion of the supported VoiceXML can be found at
87
88 http://voicexml.psychogenic.com/voicexml.php
89  
90 A summary is provided here.
91  
92  
93 VXML provides for TUI forms to be "displayed" to users (through recorded prompts), and can accept input that fills fields within the form.
94  
95 Each user input field is set based on user DTMF input, and other variables can be created and manipulated in the VXML:
96  
97  
98
99 <?xml version="1.0" ?>
100 <vxml version="2.1">
101  
102 <var name="invalidcount" />
103
104 <assign name="invalidcount" expr="0" />
105  
106 <form id="guestbox">
107 <field name="movetosel" type="digits" numdigits="1">
108
109 <prompt timeout="5s">
110
111 <audio src="/path/to/vocpmessages/guestbox500.rmd" />
112
113 <audio src="/path/to/vocpmessages/system/guestinstructions.rmd" />
114 </prompt>
115
116 <filled>
117  
118 <if cond="movetosel == 1">
119 <goto nextitem="listennext" />
120
121 <elseif cond="movetosel == 2" />
122 <goto nextitem="leaveyourown" />
123
124 <else />
125 <assign name="invalidcount" expr="invalidcount + 1" />
126 <audio src="/path/to/vocpmessages/system/invalidselection.rmd" />
127 <reprompt />
128 </if>
129 </filled>
130 </field>
131 </form>
132 </vxml>
133
134  
135 Here you can see a lot of the action. The invalidcount variable is created and set to 0. The first form encountered is entered, the prompt for the first field (movetosel) contains prompts which are played. The filled item awaits user input. Once this is received (or times out), a variable of the same name as the field is initialized with user input.
136  
137 Conditionals can check the value entered by the user, and jump to other forms within the page (or to other pages). Simple arthmetic can also be performed as demonstrated by the invalidcount counter.
138  
139 Voice recordings can be made by users through the use of a <record> item:
140  
141 <record beep="true" name="/path/to/vocpspool/500-tmp-ns3aUp4kQ.rmd" />
142
143 You may also use <goto> items to GET another page:
144
145 <goto next="vocp.cgi" />
146
147 and more complex actions may be performed by submitting data collected through a submit element:
148  
149
150 <submit next="vocp.cgi" namelist="box msgstartindex nextdirection action step" />
151  
152 would fetch the page output by the same script but would also pass along the values of each of the variables specified in the namelist.
153  
154 More information can be found at http://voicexml.psychogenic.com/
155  
156 =head2 Supported Elements
157  
158 Currently, the following VoiceXML elements are recognized and supported, at least partially:
159  
160 - assign
161 - audio
162 - block
163 - break
164 - clear
165 - disconnect
166 - else
167 - elseif
168 - field
169 - filled
170 - form
171 - goto
172 - grammar
173 - if
174 - noinput
175 - nomatch
176 - option
177 - prompt
178 - record
179 - reprompt
180 - return
181 - rule
182 - subdialog
183 - submit
184 - var
185  
186 A description and examples of each will be found in the VoiceXML section of the project site, at
187  
188 http://voicexml.psychogenic.com/voicexml.php
189
190
191  
192 =head2 Interpreter
193  
194 Variables may be set and manipulated while executing the contents of a voicexml page. The
195 Voice Extensible Markup Language specifications are, currently, far from respected in this
196 regard within VoiceXML::Client. Instead of using a full ECMAScript interpreter, a simple
197 Perl interpreter was created that is, to date, sufficient for most of our requirements.
198  
199 What is available includes, variable creation:
200  
201 <var name="invalidcount" />
202 <var name="filetoplay" />
203  
204  
205 and assignment:
206
207 <assign name="invalidcount" expr="0" />
208 <assign name="filetoplay" expr="'/path/to/a/file.rmd'" />
209  
210 Note that, unlike numeric values, strings need to be 'quoted'. Comparison operators may be used in the
211 cond attribute of if/elseif elements, and simple arithmetic may be performed in expr attributes:
212  
213  
214 <if cond="movetosel == 1">
215 <goto nextitem="listennext" />
216
217 <elseif cond="movetosel == 2" />
218 <goto nextitem="leaveyourown" />
219
220 <elseif cond="movetosel &gt; 5 />
221 <assign name="invalidcount" expr="invalidcount + 1" />
222 <reprompt />
223 <else />
224 <submit next="somewhereelse.cgi" namelist="filetoplay movetosel" />
225 </if>
226  
227 Note here that <, >, <= and >= must be HTML encoded.
228  
229 Variables may also be used in places like <audio> tags, instead of explicitly setting the src you can:
230  
231
232 <audio expr="filetoplay" />
233  
234 Since this is a variable name, it is not 'quoted'... that's why the file played is whatever is set in the
235 filetoplay variable, rather than a file called 'filetoplay'.
236  
237 This implementation is far from complete and has a number of limitations (e.g. though expr="invalidcount + 1"
238 currently works, changing the order or adding two variables would likely fail) but a number of examples can
239 be seen within the included exampleBBSBox.vxml file and on http://voicexml.psychogenic.com/
240  
241 If you stick to these conventions, you're vxml will work now and in the future, when a true
242 interpreter is developed for or incorporated within VoiceXML::Client.
243  
244  
245 =head1 SEE ALSO
246  
247 Detailed documentation is available on the project site at
248  
249
250 http://voicexml.psychogenic.com/
251  
252  
253 VoiceXML::Client was created as a supporting component of the second version of the
254 VOCP voice messaging system (http://www.vocpsystem.com).
255  
256 It relies on the capabilities of the pure perl XML::Mini xml parser (http://minixml.psychogenic.com/)
257  
258  
259 =head1 AUTHOR
260  
261 Pat Deegan, http://www.psychogenic.com
262  
263 =head1 COPYRIGHT AND LICENSE
264  
265
266 Copyright (C) 2007,2008 by Pat Deegan.
267 All rights reserved
268 http://voicexml.psychogenic.com
269  
270 This library is released under the terms of the GNU GPL version 3, making it available only for
271 free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details).
272 Anyone wishing to use this library within a proprietary or otherwise non-GPLed program MUST contact psychogenic.com to
273 acquire a distinct license for their application. This approach encourages the use of free software
274 while allowing for proprietary solutions that support further development.
275  
276  
277 This file is part of VoiceXML::Client.
278  
279
280
281 VoiceXML::Client is free software: you can redistribute it and/or modify
282 it under the terms of the GNU General Public License as published by
283 the Free Software Foundation, either version 3 of the License, or
284 (at your option) any later version.
285  
286 VoiceXML::Client is distributed in the hope that it will be useful,
287 but WITHOUT ANY WARRANTY; without even the implied warranty of
288 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
289 GNU General Public License for more details.
290  
291 You should have received a copy of the GNU General Public License
292 along with VoiceXML::Client. If not, see <http://www.gnu.org/licenses/>.
293  
294  
295  
296 =cut
297  
298  
299 3 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
300 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
301 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
302  
303 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
304  
305 3 ▶use VoiceXML::Client::DeviceHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
306 3 ▶use VoiceXML::Client::Device::Dummy;
Subroutine BEGIN: called CC=1 SCAR=0.0
307 3 ▶use VoiceXML::Client::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
308  
309 3 ▶use vars qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
310 $Debug
311 3 };
312  
313 3 $Debug = 0;
314  
315 # get rid of annoying deep recursion warnings from XML::Mini...
316 0 ▶$SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
317 0 my $msg = shift;
318 0 ▶ print STDERR $msg if ($msg !~ /Deep recursion/);
Branch: 1 branch
BranchTrueFalseTotal
if not $msg =~ /Deep recursion/ 0 0 0
319 3 };
320  
321 3 require Exporter;
322 3 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
323  
324 3 our @ISA = qw(Exporter);
325  
326  
327 # will save memory.
328 3 our %EXPORT_TAGS = ( 'all' => [ qw(
329
330 ) ] );
331  
332 3 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
333  
334 3 our @EXPORT = qw(
335
336 );
337  
338 3 our $VERSION = '1.01';
339  
340  
341  
342  
343 3 1;
344 __END__
« Client/Item/Assign.pm ↑ Summary Client/Item/NoInput.pm »