| 1 | package VoiceXML::Client::UserAgent; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use VoiceXML::Client::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Hash::Util qw(lock_hash); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use HTTP::Cookies; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use VoiceXML::Client::Engine::Component::Interpreter::Perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 3 | ▶ | use vars qw{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | $VERSION | ||||||||||||||||||||||||||||
| 52 | %Directive | ||||||||||||||||||||||||||||
| 53 | 3 | }; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 3 | $VERSION = '1.0.0'; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 3 | %Directive = ( | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||
| 60 | 3 | Hash::Util::lock_hash(%Directive); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $domain = shift || 'localhost'; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'localhost'
MC/DC0%0/1
shift() || 'localhost'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $basepath = shift || '/'; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || '/'
MC/DC0%0/1
shift() || '/'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $params = shift || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | bless $self, ref $class || $class; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | $self->{'domain'} = $domain; | |||||||||||||||||||||||||||
| 73 | 0 | $self->{'basepath'} = $basepath; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if (exists $params->{'agent'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | 0 | $self->{'agent'} = $params->{'agent'}; | |||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||
| 79 | 0 | $self->{'agent'} = "VoiceXML::Client VOCP VoiceBrowser/$VERSION"; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if (exists $params->{'protocol'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||
| 84 | 0 | $self->{'protocol'} = $params->{'protocol'}; | |||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | 0 | $self->{'protocol'} = 'http'; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (exists $params->{'runtime'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 0 | $self->{'runtime'} = $params->{'runtime'}; | |||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||
| 93 | 0 | $self->{'runtime'} = VoiceXML::Client::Engine::Component::Interpreter::Perl->runtime(); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if (exists $params->{'errormsgfile'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||
| 98 | 0 | $self->{'errormsgfile'} = $params->{'errormsgfile'}; | |||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||
| 100 | 0 | $self->{'errormsgfile'} = ''; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | $self->initUA($params); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $self->{'vxmlparser'} = new VoiceXML::Client::Parser || die "Could not create parser??"; | ||||||||||||||||||||||||||
|
Condition0%0/2
'VoiceXML::Client::Parser'->new || die('Could not create parser??')
MC/DC0%0/1
'VoiceXML::Client::Parser'->new || die('Could not create parser??')
'VoiceXML::Client::Parser'->new
Truth table0%0/2
A
A= 'VoiceXML::Client::Parser'->new
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | return $self; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub initUA { | ||||||||||||||||||||||||||
|
Subroutine
initUA: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 0 | my $params = shift; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | unless (exists $self->{'cookiejar'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | my %cookieParams = ( | |||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ($params->{'cookiefile'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||
| 123 | 0 | $cookieParams{'file'} = $params->{'cookiefile'}; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | $self->{'cookiejar'} = HTTP::Cookies->new( %cookieParams ); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | $self->{'ua'} = LWP::UserAgent->new( | ||||||||||||||||||||||||||||
| 130 | 'agent' => $self->{'agent'}, | ||||||||||||||||||||||||||||
| 131 | 0 | 'cookie_jar' => $self->{'cookiejar'}, | |||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | return 1; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub constructFullURL { | ||||||||||||||||||||||||||
|
Subroutine
constructFullURL: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 137 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 138 | 0 | ▶ | my $url = shift || '' ; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ($url !~ m|^\w+://|) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | # not full url... | ||||||||||||||||||||||||||||
| 143 | 0 | my $fullURL = $self->{'protocol'} . '://' . $self->{'domain'}; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($url !~ m|^/|) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||
| 147 | # not full path... | ||||||||||||||||||||||||||||
| 148 | 0 | $fullURL .= $self->{'basepath'}; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | $fullURL .= $url; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | VoiceXML::Client::Util::log_msg("constructFullURL return $fullURL"); | |||||||||||||||||||||||||||
| 154 | 0 | return $fullURL; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # it is full already... | ||||||||||||||||||||||||||||
| 158 | 0 | return $url; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 162 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 163 | 0 | my $url = shift; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | return $self->{'ua'}->get($self->constructFullURL($url)); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub post { | ||||||||||||||||||||||||||
|
Subroutine
post: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 170 | 0 | my $url = shift ; | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $data = shift || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | return $self->{'ua'}->get($self->constructFullURL($url), $data); | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub runApplication { | ||||||||||||||||||||||||||
|
Subroutine
runApplication: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 177 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $url = shift || die "VoiceXML::Client::UserAgent::runApplication MUST pass start URL"; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || die('VoiceXML::Client::UserAgent::runApplication MUST pass start URL')
MC/DC0%0/1
shift() || die('VoiceXML::Client::UserAgent::runApplication MUST pass start URL')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | my $deviceHandle = shift || die "VoiceXML::Client::UserAgent::runApplication MUST pass device handle"; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || die('VoiceXML::Client::UserAgent::runApplication MUST pass device handle')
MC/DC0%0/1
shift() || die('VoiceXML::Client::UserAgent::runApplication MUST pass device handle')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | my $itemExecParams = { | |||||||||||||||||||||||||||
| 183 | 'errormsgfile' => $self->errorMessageFile() | ||||||||||||||||||||||||||||
| 184 | }; | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | my $retVal; | |||||||||||||||||||||||||||
| 187 | 0 | my $docCount = 0; | |||||||||||||||||||||||||||
| 188 | do { | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | my $response = $self->get($url); | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | ▶ | unless ($response->is_success) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | { | ||||||||||||||||||||||||||||
| 194 | 0 | warn "Could not fetch document $url"; | |||||||||||||||||||||||||||
| 195 | 0 | die $response->status_line; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | $docCount++; | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | my $vxmlFileContents = $response->content; | |||||||||||||||||||||||||||
| 201 | 0 | ▶ | print STDERR "$vxmlFileContents" if ($VoiceXML::Client::Debug > 2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my $vxmlDoc = $self->{'vxmlparser'}->parse($vxmlFileContents, $self->{'runtime'}) || die "Could not parse response from $url"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'vxmlparser'}->parse($vxmlFileContents, $self->{'runtime'}) || die("Could not parse response from $url")
MC/DC0%0/1
$self->{'vxmlparser'}->parse($vxmlFileContents, $self->{'runtime'}) || die("Could not parse response from $url")
$self->{'vxmlparser'}->parse($vxmlFileContents, $self->{'runtime'})
Truth table0%0/2
A
A= $self->{'vxmlparser'}->parse($vxmlFileContents, $self->{'runtime'})
| |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | $retVal = $vxmlDoc->execute($deviceHandle, $itemExecParams); | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ($retVal == $VoiceXML::Client::Flow::Directive{'NEXTDOC'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||
| 209 | 0 | $url = $vxmlDoc->nextDocument(); | |||||||||||||||||||||||||||
| 210 | 0 | ▶ | die "Told to go to next doc, but nextDocument not set" unless ($url); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | } while ($retVal == $VoiceXML::Client::Flow::Directive{'NEXTDOC'}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | VoiceXML::Client::Util::log_msg("Application completed ($retVal) after $docCount fetches"); | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | return ; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | sub errorMessageFile { | ||||||||||||||||||||||||||
|
Subroutine
errorMessageFile: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 222 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 223 | 0 | my $setTo = shift; | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if (defined $setTo && -r $setTo) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $setTo and -r $setTo
MC/DC0%0/2
defined $setTo and -r $setTo
defined $setTo
-r $setTo
Truth table0%0/3
A and B
A= defined $setToB= -r $setTo
| |||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||
| 227 | 0 | $self->{'errormsgfile'} = $setTo; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | return $self->{'errormsgfile'}; | |||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 3 | 1; | |||||||||||||||||||||||||||