Client/Item.pm

filter: Statementstmt 83.3% 125 / 150 Branchbran 68.5% 37 / 54 Conditioncond 25.8% 8 / 31 MC/DCmcdc 5.5% 1 / 18 Subroutinesub 82.1% 23 / 28 Podpod 9.5% 2 / 21 totaltotal 64.9% 196 / 302 CC 41 SCAR 20.6
CC
41
Cov
72%
getContext
42.0
new
10.6
createChildren
8.2
CRAP 7.8
« Client/DeviceHandle.pm ↑ Summary Client/Item/Audio.pm »
1 package VoiceXML::Client::Item;
2  
3 3 ▶use VoiceXML::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use VoiceXML::Client::Item::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use VoiceXML::Client::Flow;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use VoiceXML::Client::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Hash::Util qw(lock_hash);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use vars qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
13 $VERSION
14 3 };
15  
16  
17 3 $VERSION = $VoiceXML::Client::VERSION;
18  
19  
20 =head1 COPYRIGHT AND LICENSE
21  
22
23 Copyright (C) 2007,2008 by Pat Deegan.
24 All rights reserved
25 http://voicexml.psychogenic.com
26  
27 This library is released under the terms of the GNU GPL version 3, making it available only for
28 free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details).
29 Anyone wishing to use this library within a proprietary or otherwise non-GPLed program MUST contact psychogenic.com to
30 acquire a distinct license for their application. This approach encourages the use of free software
31 while allowing for proprietary solutions that support further development.
32  
33  
34 This file is part of VoiceXML::Client.
35  
36
37
38 VoiceXML::Client is free software: you can redistribute it and/or modify
39 it under the terms of the GNU General Public License as published by
40 the Free Software Foundation, either version 3 of the License, or
41 (at your option) any later version.
42  
43 VoiceXML::Client is distributed in the hope that it will be useful,
44 but WITHOUT ANY WARRANTY; without even the implied warranty of
45 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 GNU General Public License for more details.
47  
48 You should have received a copy of the GNU General Public License
49 along with VoiceXML::Client. If not, see <http://www.gnu.org/licenses/>.
50  
51  
52 =cut
53  
54 =head2 new XMLELEMENTOBJ PARENTOBJ [PARAMS]
55  
56  
57 Creates a new instance of the appropriate class. Parses all children elements and then calls init, passing the
58 optional PARAMS href (init() exists to be overridden in subclasses, where required.).
59  
60  
61 =cut
62  
63 59 ▶sub new {
Subroutine new: called CC=8 SCAR=23.6
Pod documented
64 59 my $class = shift;
65 59 ▶ my $xmlElement = shift || return VoiceXML::Client::Util::error("VoiceXML::Client::Item::Factory::new() Must pass an XML element to new.");
Condition50%1/2
shift() || (return VoiceXML::Client::Util::error('VoiceXML::Client::Item::Factory::new() Must pass an XML element to new.'))
l!l
590
MC/DC0%0/1
shift() || (return VoiceXML::Client::Util::error('VoiceXML::Client::Item::Factory::new() Must pass an XML element to new.'))
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
66 59 my $parent = shift;
67 59 my $params = shift;
68
69
70 59 my $self = {};
71
72 59 ▶ bless $self, ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0590
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
73
74 59 ▶ $self->{'type'} = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0590
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
75 59 $self->{'XMLElement'} = $xmlElement;
76 59 $self->{'parent'} = $parent;
77
78
79 59 ▶ if ($params && ref $params && exists $params->{'context'})
Branch: 1 branch
BranchTrueFalseTotal
if ($params and ref $params and exists $params->{'context'}) { } 0 59 59
Condition33%2/6
$params and ref $params and exists $params->{"context"}
!ll&&!rl&&r
5900
$params and ref $params
!ll&&!rl&&r
5900
MC/DC0%0/3
$params and ref $params and exists $params->{"context"}
$params ref $params exists $params->{"context"}
Truth table25%1/4
A and B and C
A= $paramsB= ref $paramsC= exists $params->{"context"}
ABCresult
0XX0
10X0
1100
1111
80 {
81 0 $self->{'_context'} = $params->{'context'};
82 } else {
83 59 $self->{'_context'} = undef;
84 }
85
86 59 $self->{'currentchild'} = 0;
87
88 59 my $retVal = $self->init($params);
89 59 ▶ return $retVal unless ($retVal); # if init didn't go well, we say so here and skip the kids...
Branch: 1 branch
BranchTrueFalseTotal
unless $retVal 0 59 59
90
91 # create children lastly
92 59 $self->createChildren();
93
94 59 return $self;
95 }
96  
97 9 ▶sub getType {
Subroutine getType: called CC=1 SCAR=0.0
Pod undocumented
98 9 my $self = shift;
99
100 9 return $self->{'type'};
101 }
102  
103
104  
105 59 ▶sub createChildren {
Subroutine createChildren: called CC=8 SCAR=21.0
Pod undocumented
106 59 my $self = shift;
107 59 my $params = shift;
108
109 59 my $children = $self->{'XMLElement'}->getAllChildren();
110
111 59 my $numChildren = scalar @{$children};
112  
113
114 59 $self->{'children'} = [];
115 59 my $itemCount = 0;
116 59 ▶ for (my $i=0; $i<$numChildren; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numChildren) 50 59 109
117 {
118 50 my $name = $children->[$i]->name();
119
120 50 ▶ if ($name eq 'var')
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "var") 3 47 50
121 {
122 # Variable declaration - ensure we have an interpreter context in this scope
123
124 3 my $varName = $children->[$i]->attribute('name');
125 3 ▶ if (defined $varName)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $varName) 3 0 3
126 {
127 3 $self->{'declaredVariables'}->{$varName}++;
128 }
129 3 ▶ $self->createContext() unless ($self->{'_context'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_context"} 1 2 3
130 }
131
132 50 my $newItem = VoiceXML::Client::Item::Factory->newItem($name, $children->[$i], $self);
133
134 50 ▶ unless (defined $newItem)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $newItem) 3 47 50
135 {
136 3 VoiceXML::Client::Util::log_msg("VoiceXML::Client::Item::init() Don't yet know how to deal with '$name' elements - skipping");
137 3 next;
138 }
139
140 47 ▶ if ($newItem)
Branch: 1 branch
BranchTrueFalseTotal
if ($newItem) { } 47 0 47
141 {
142 47 $self->{'children'}->[$itemCount++] = $newItem;
143 } else {
144 0 ▶ VoiceXML::Client::Util::log_msg("VoiceXML::Client::Item::init() skipping creation of '$name' element")
Branch: 1 branch
BranchTrueFalseTotal
if $VoiceXML::Client::Debug 0 0 0
145 if ($VoiceXML::Client::Debug);
146 }
147  
148
149 }
150
151 59 return $itemCount;
152 }
153  
154
155
156  
157 0 ▶sub getChildrenImmediate {
Subroutine getChildrenImmediate: not called CC=1 SCAR=6.9
Pod undocumented
158 0 my $self = shift;
159
160 0 return $self->{'children'};
161 }
162  
163 0 ▶sub getChildrenRecursive {
Subroutine getChildrenRecursive: not called CC=2 SCAR=17.9
Pod undocumented
164 0 my $self = shift;
165
166 0 my @results;
167
168 0 foreach my $child (@{$self->{'children'}})
169 {
170 0 push @results, $child;
171 0 my $grandChildren = $child->getChildrenRecursive();
172
173 0 push @results, @{$grandChildren};
174 }
175
176 0 return \@results;
177 }
178  
179  
180 0 ▶sub getAttribute {
Subroutine getAttribute: not called CC=2 SCAR=17.9
Pod undocumented
181 0 my $self = shift;
182 0 ▶ my $attrname = shift || return undef;
Condition0%0/2
shift() || (return undef)
l!l
00
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
183
184 0 return $self->{'XMLElement'}->attribute($attrname);
185 }
186
187  
188 =head2 init [PARAMS]
189  
190 Called by new(), override in derived classes to implement subclass-specific initialisation.
191  
192 =cut
193  
194 10 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
195 10 my $self = shift;
196 10 my $params = shift;
197
198 10 return 1;
199 }
200  
201  
202 2 ▶sub getRuntime {
Subroutine getRuntime: called CC=3 SCAR=11.3
Pod undocumented
203 2 my $self = shift;
204
205 2 ▶ if (defined $self->{'_runtime'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_runtime'}) { } 1 1 2
206 {
207 1 return $self->{'_runtime'};
208 } else {
209 return $self->{'parent'}->getRuntime()
210 1 ▶ if ($self->{'parent'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parent"} 1 0 1
211 }
212  
213 0 return undef;
214 }
215  
216 0 ▶sub getContext {
Subroutine getContext: not called CC=6 SCAR=37.4
Pod undocumented
217 0 my $self = shift;
218
219 return $self->{'_context'}
220 0 ▶ if (exists $self->{'_context'} && defined $self->{'_context'} && $self->{'_context'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_context"} and defined $self->{"_context"} and $self->{"_context"} 0 0 0
Condition0%0/6
exists $self->{"_context"} and defined $self->{"_context"} and $self->{"_context"}
!ll&&!rl&&r
000
exists $self->{"_context"} and defined $self->{"_context"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $self->{"_context"} and defined $self->{"_context"} and $self->{"_context"}
exists $self->{"_context"} defined $self->{"_context"} $self->{"_context"}
Truth table0%0/4
A and B and C
A= exists $self->{"_context"}B= defined $self->{"_context"}C= $self->{"_context"}
ABCresult
0XX0
10X0
1100
1111
221
222 0 ▶ return $self->{'parent'}->getContext if (defined $self->{'parent'} && $self->{'parent'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"parent"} and $self->{"parent"} 0 0 0
Condition0%0/3
defined $self->{"parent"} and $self->{"parent"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"parent"} and $self->{"parent"}
defined $self->{"parent"} $self->{"parent"}
Truth table0%0/3
A and B
A= defined $self->{"parent"}B= $self->{"parent"}
ABresult
0X0
100
111
223
224 0 return undef;
225 }
226  
227 1 ▶sub createContext {
Subroutine createContext: called CC=2 SCAR=7.4
Pod undocumented
228 1 my $self = shift;
229
230 1 ▶ my $runtime = $self->getRuntime() || VoiceXML::Client::Util::error("VoiceXML::Client::Item::createContext() Could not find runtime!");
Condition33%1/3
$self->getRuntime || VoiceXML::Client::Util::error('VoiceXML::Client::Item::createContext() Could not find runtime!')
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->getRuntime || VoiceXML::Client::Util::error('VoiceXML::Client::Item::createContext() Could not find runtime!')
$self->getRuntime VoiceXML::Client::Util::error('VoiceXML::Client::Item::createContext() Could not find runtime!')
Truth table33%1/3
A || B
A= $self->getRuntimeB= VoiceXML::Client::Util::error('VoiceXML::Client::Item::createContext() Could not find runtime!')
ABresult
1X1
011
000
231
232 1 $self->{'_context'} = $runtime->create_context();
233
234 1 return $self->{'_context'};
235
236 }
237  
238  
239 16 ▶sub abortProcessing {
Subroutine abortProcessing: called CC=2 SCAR=7.0
Pod undocumented
240 16 my $self = shift;
241 16 my $setTo = shift; # optional
242
243 16 ▶ if (defined $setTo)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $setTo) 16 0 16
244 {
245 16 $self->{'_abortprocessing'} = $setTo;
246 }
247
248 16 return $self->{'_abortprocessing'};
249 }
250  
251 45 ▶sub shouldContinueProcessing {
Subroutine shouldContinueProcessing: called CC=3 SCAR=11.0
Pod undocumented
252 45 my $self = shift;
253
254 45 ▶ return 0 if ($self->{'_abortprocessing'}); # this item think I should continue...
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_abortprocessing"} 0 45 45
255
256 45 ▶ return $self->{'parent'}->shouldContinueProcessing() if ($self->{'parent'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parent"} 26 19 45
257
258 19 return 1;
259 }
260  
261 16 ▶sub reset {
Subroutine reset: called CC=3 SCAR=11.0
Pod undocumented
262 16 my $self = shift;
263  
264 16 ▶ VoiceXML::Client::Util::log_msg("item reset() called") if ($VoiceXML::Client::Debug > 3);
Branch: 1 branch
BranchTrueFalseTotal
if $VoiceXML::Client::Debug > 3 0 16 16
265
266 16 $self->abortProcessing(0);
267 16 foreach my $child (@{$self->{'children'}})
268 {
269 13 $child->reset();
270 }
271
272 16 $self->resetChildPositionIndex();
273 }
274  
275  
276 19 ▶sub resetChildPositionIndex {
Subroutine resetChildPositionIndex: called CC=4 SCAR=13.9
Pod undocumented
277 19 my $self = shift;
278
279 19 ▶ if (scalar @{$self->{'children'}})
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{"children"};}) 3 16 19
280 {
281 3 ▶ for (my $i=0; $i <= $self->{'currentchild'}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $self->{"currentchild"}) 3 3 6
282 {
283
284 3 ▶ if ($self->{'children'}->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"children"}[$i]) 3 0 3
285 {
286 3 $self->{'children'}->[$i]->resetChildPositionIndex();
287 }
288 }
289
290 }
291
292 19 $self->{'currentchild'} = 0;
293
294 19 return ;
295 }
296  
297 14 ▶sub proceedToNextChild {
Subroutine proceedToNextChild: called CC=1 SCAR=0.0
Pod undocumented
298 14 my $self = shift;
299
300 14 return $self->{'currentchild'}++;
301
302 }
303
304 37 ▶sub getCurrentChild {
Subroutine getCurrentChild: called CC=2 SCAR=6.9
Pod undocumented
305 37 my $self = shift;
306
307 37 ▶ return undef unless ($self->{'currentchild'} < scalar @{$self->{'children'}});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"currentchild"} < scalar @{$self->{"children"};} 18 19 37
308
309 19 return $self->{'children'}->[$self->{'currentchild'}];
310 }
311  
312  
313 6 ▶sub execute {
Subroutine execute: called CC=1 SCAR=0.0
Pod undocumented
314 6 my $self = shift;
315 6 my $handle = shift;
316 6 my $optParms = shift;
317
318
319 6 return $self->executeChildren($handle, $optParms);
320 }
321  
322 24 ▶sub executeChildren {
Subroutine executeChildren: called CC=4 SCAR=13.9
Pod undocumented
323 24 my $self = shift;
324 24 my $handle = shift;
325 24 my $optParms = shift;
326
327 24 ▶ while ((my $curChild = $self->getCurrentChild()) && $self->shouldContinueProcessing())
Branch: 1 branch
BranchTrueFalseTotal
if (my $curChild = $self->getCurrentChild and $self->shouldContinueProcessing) 19 18 37
Condition66%2/3
my $curChild = $self->getCurrentChild and $self->shouldContinueProcessing
!ll&&!rl&&r
18019
MC/DC50%1/2
my $curChild = $self->getCurrentChild and $self->shouldContinueProcessing
my $curChild = $self->getCurrentChild $self->shouldContinueProcessing
Truth table66%2/3
A and B
A= my $curChild = $self->getCurrentChildB= $self->shouldContinueProcessing
ABresult
0X0
100
111
328 {
329
330 19 my $rv = $curChild->execute($handle, $optParms) ;
331
332
333 19 ▶ return $rv if ($rv != $VoiceXML::Client::Flow::Directive{'CONTINUE'});
Branch: 1 branch
BranchTrueFalseTotal
if $rv != $VoiceXML::Client::Flow::Directive{"CONTINUE"} 6 13 19
334
335 13 $self->proceedToNextChild();
336 }
337
338 18 return $VoiceXML::Client::Flow::Directive{'CONTINUE'};
339
340 }
341  
342  
343  
344  
345  
346 145 ▶sub getParentVXMLDocument {
Subroutine getParentVXMLDocument: called CC=3 SCAR=11.2
Pod undocumented
347 145 my $self = shift;
348
349 145 ▶ if ($self->can('isaVXMLDocument'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("isaVXMLDocument")) 53 92 145
350 {
351 53 return $self;
352 }
353
354 92 ▶ if ($self->{'parent'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"parent"}) 92 0 92
355 {
356 92 return $self->{'parent'}->getParentVXMLDocument();
357 }
358
359 0 return undef;
360 }
361  
362 6 ▶sub getParentForm {
Subroutine getParentForm: called CC=3 SCAR=11.2
Pod undocumented
363 6 my $self = shift;
364
365 6 ▶ if ($self->can('isaFormItem'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("isaFormItem")) 3 3 6
366 {
367 3 return $self;
368 }
369
370 3 ▶ if ($self->{'parent'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"parent"}) 3 0 3
371 {
372 3 return $self->{'parent'}->getParentForm();
373 }
374
375 0 return undef;
376 }
377  
378 0 ▶sub toString {
Subroutine toString: not called CC=1 SCAR=6.9
Pod undocumented
379 0 my $self = shift;
380
381 0 return $self->{'XMLElement'}->toString();
382 }
383  
384 3 1;
« Client/DeviceHandle.pm ↑ Summary Client/Item/Audio.pm »