Client/Parser.pm

filter: Statementstmt 95.8% 46 / 48 Branchbran 50.0% 10 / 20 Conditioncond 37.5% 6 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 68.6% 70 / 102 CC 17 SCAR 27.5
CC
17
Cov
74%
parse
22.1
new
3.2
BEGIN
1.0
CRAP 15.7
« Client/Item/Submit.pm ↑ Summary Client/Item/Grammar.pm »
1 package VoiceXML::Client::Parser;
2  
3 3 ▶use XML::Mini::Document;
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::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10  
11 =head1 COPYRIGHT AND LICENSE
12  
13
14 Copyright (C) 2007,2008 by Pat Deegan.
15 All rights reserved
16 http://voicexml.psychogenic.com
17  
18 This library is released under the terms of the GNU GPL version 3, making it available only for
19 free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details).
20 Anyone wishing to use this library within a proprietary or otherwise non-GPLed program MUST contact psychogenic.com to
21 acquire a distinct license for their application. This approach encourages the use of free software
22 while allowing for proprietary solutions that support further development.
23  
24  
25 This file is part of VoiceXML::Client.
26  
27
28
29 VoiceXML::Client is free software: you can redistribute it and/or modify
30 it under the terms of the GNU General Public License as published by
31 the Free Software Foundation, either version 3 of the License, or
32 (at your option) any later version.
33  
34 VoiceXML::Client is distributed in the hope that it will be useful,
35 but WITHOUT ANY WARRANTY; without even the implied warranty of
36 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 GNU General Public License for more details.
38  
39 You should have received a copy of the GNU General Public License
40 along with VoiceXML::Client. If not, see <http://www.gnu.org/licenses/>.
41  
42  
43 =cut
44  
45 =head2 new [FILE]
46  
47 Creates a new instance
48  
49  
50 =cut
51  
52 3 ▶sub new {
Subroutine new: called CC=3 SCAR=11.6
Pod documented
53 3 my $class = shift;
54 3 my $file = shift;
55
56 3 my $self = {};
57
58 3 ▶ bless $self, ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
59
60 3 ▶ $self->parse($file) if ($file);
Branch: 1 branch
BranchTrueFalseTotal
if $file 0 3 3
61
62
63 3 return $self;
64 }
65  
66  
67 =head2 parse FILE
68  
69 Parses VXML file FILE and returns the VoiceXML::Client::Document object.
70  
71 =cut
72  
73 3 ▶sub parse {
Subroutine parse: called CC=15 SCAR=31.0
Pod documented
74 3 my $self = shift;
75 3 ▶ my $fileOrString = shift || die "VoiceXML::Client::Parser::parse MUST pass string or file";
Condition50%1/2
shift() || die('VoiceXML::Client::Parser::parse MUST pass string or file')
l!l
30
MC/DC0%0/1
shift() || die('VoiceXML::Client::Parser::parse MUST pass string or file')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
76 3 ▶ my $runtime = shift || die "VoiceXML::Client::Parser::parse MUST pass runtime";
Condition50%1/2
shift() || die('VoiceXML::Client::Parser::parse MUST pass runtime')
l!l
30
MC/DC0%0/1
shift() || die('VoiceXML::Client::Parser::parse MUST pass runtime')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
77
78 3 $self->{'_XMLDoc'} = XML::Mini::Document->new();
79 3 $self->{'vxml'} = []; # make sure we're nice and empty
80
81 3 my $numChildrenFound;
82 3 ▶ if ($fileOrString =~ m/\n/ || length($fileOrString) > 250)
Branch: 1 branch
BranchTrueFalseTotal
if ($fileOrString =~ /\n/ or length $fileOrString > 250) { } 0 3 3
Condition33%1/3
$fileOrString =~ /\n/ or length $fileOrString > 250
l!l&&r!l&&!r
003
MC/DC0%0/2
$fileOrString =~ /\n/ or length $fileOrString > 250
$fileOrString =~ /\n/ length $fileOrString > 250
Truth table33%1/3
A or B
A= $fileOrString =~ /\n/B= length $fileOrString > 250
ABresult
1X1
011
000
83 {
84 # it is VXML content?
85 # TODO: Need a better test...
86 0 $numChildrenFound = $self->{'_XMLDoc'}->fromString($fileOrString);
87
88 0 ▶ VoiceXML::Client::Util::error("VoiceXML::Client::Parser::parse() No xml children found in string ")
Branch: 1 branch
BranchTrueFalseTotal
unless $numChildrenFound 0 0 0
89 unless($numChildrenFound);
90 } else {
91
92 3 ▶ VoiceXML::Client::Util::error("VoiceXML::Client::Parser::parse() Must pass a filename or contents")
Branch: 1 branch
BranchTrueFalseTotal
unless $fileOrString 0 3 3
93 unless ($fileOrString);
94
95 3 ▶ VoiceXML::Client::Util::error("VoiceXML::Client::Parser::parse() Can't find file '$fileOrString'")
Branch: 1 branch
BranchTrueFalseTotal
unless -e $fileOrString 0 3 3
96 unless(-e $fileOrString);
97
98 3 ▶ VoiceXML::Client::Util::error("VoiceXML::Client::Parser::parse() Can't read file '$fileOrString'")
Branch: 1 branch
BranchTrueFalseTotal
unless -r $fileOrString 0 3 3
99 unless(-r $fileOrString);
100
101 3 ▶ $numChildrenFound = $self->{'_XMLDoc'}->fromFile($fileOrString) if ($fileOrString);
Branch: 1 branch
BranchTrueFalseTotal
if $fileOrString 3 0 3
102
103 3 ▶ VoiceXML::Client::Util::error("VoiceXML::Client::Parser::parse() No xml children found in $fileOrString")
Branch: 1 branch
BranchTrueFalseTotal
unless $numChildrenFound 0 3 3
104 unless($numChildrenFound);
105 }
106
107 #print $self->{'_XMLDoc'}->toString(); exit(0);
108
109
110 3 $self->{'_XMLRoot'} = $self->{'_XMLDoc'}->getRoot();
111
112 3 $self->{'itemFactory'} = VoiceXML::Client::Item::Factory->new();
113
114
115 3 ▶ my $vxmlElement = $self->{'_XMLRoot'}->getElement('vxml')
Condition33%1/3
$self->{'_XMLRoot'}->getElement('vxml') || VoiceXML::Client::Util::error('VoiceXML::Client::Parser::parse() no vxml element found in document.')
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->{'_XMLRoot'}->getElement('vxml') || VoiceXML::Client::Util::error('VoiceXML::Client::Parser::parse() no vxml element found in document.')
$self->{'_XMLRoot'}->getElement('vxml') VoiceXML::Client::Util::error('VoiceXML::Client::Parser::parse() no vxml element found in document.')
Truth table33%1/3
A || B
A= $self->{'_XMLRoot'}->getElement('vxml')B= VoiceXML::Client::Util::error('VoiceXML::Client::Parser::parse() no vxml element found in document.')
ABresult
1X1
011
000
116 || VoiceXML::Client::Util::error("VoiceXML::Client::Parser::parse() no vxml element found in document.");
117
118 3 my $vxmlChildren = $vxmlElement->getAllChildren();
119 3 my $numChildren = scalar(@{$vxmlChildren});
120
121 3 ▶ VoiceXML::Client::Util::error("VoiceXML::Client::Parser::parse() no form elements found in vxml element.")
Branch: 1 branch
BranchTrueFalseTotal
unless $numChildren 0 3 3
122 unless ($numChildren);
123
124
125 3 my $docname = $fileOrString;
126 3 $docname =~ s|^.*/||;
127
128 3 $self->{'VXMLDoc'} = VoiceXML::Client::Document->new($docname, $runtime);
129
130 3 ▶ for(my $i=0; $i < $numChildren; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numChildren) 12 3 15
131 {
132 12 ▶ my $name = $vxmlChildren->[$i]->name() || VoiceXML::Client::Util::error("No name for child $i in VoiceXML::Client::Parser::parse()");
Condition33%1/3
$vxmlChildren->[$i]->name || VoiceXML::Client::Util::error("No name for child $i in VoiceXML::Client::Parser::parse()")
l!l&&r!l&&!r
1200
MC/DC0%0/2
$vxmlChildren->[$i]->name || VoiceXML::Client::Util::error("No name for child $i in VoiceXML::Client::Parser::parse()")
$vxmlChildren->[$i]->name VoiceXML::Client::Util::error("No name for child $i in VoiceXML::Client::Parser::parse()")
Truth table33%1/3
A || B
A= $vxmlChildren->[$i]->nameB= VoiceXML::Client::Util::error("No name for child $i in VoiceXML::Client::Parser::parse()")
ABresult
1X1
011
000
133 12 $self->{'vxml'}->[$i] = $self->{'itemFactory'}->newItem($name, $vxmlChildren->[$i], $self->{'VXMLDoc'});
134
135 }
136
137 3 $self->{'VXMLDoc'}->addItem($self->{'vxml'});
138
139 3 return $self->{'VXMLDoc'};
140 }
141  
142 3 1;
« Client/Item/Submit.pm ↑ Summary Client/Item/Grammar.pm »