| 1 | |||||||||||||||||||||
| 2 | package VoiceXML::Client::Item::Grammar; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 3 | ▶ | use base qw (VoiceXML::Client::Item); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 3 | ▶ | use VoiceXML::Client::Util; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | Copyright (C) 2007,2008 by Pat Deegan. | ||||||||||||||||||||
| 13 | All rights reserved | ||||||||||||||||||||
| 14 | http://voicexml.psychogenic.com | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | This library is released under the terms of the GNU GPL version 3, making it available only for | ||||||||||||||||||||
| 17 | free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details). | ||||||||||||||||||||
| 18 | Anyone wishing to use this library within a proprietary or otherwise non-GPLed program MUST contact psychogenic.com to | ||||||||||||||||||||
| 19 | acquire a distinct license for their application. This approach encourages the use of free software | ||||||||||||||||||||
| 20 | while allowing for proprietary solutions that support further development. | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | This file is part of VoiceXML::Client. | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | VoiceXML::Client is free software: you can redistribute it and/or modify | ||||||||||||||||||||
| 28 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||
| 29 | the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||
| 30 | (at your option) any later version. | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | VoiceXML::Client is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 33 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 34 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||
| 35 | GNU General Public License for more details. | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | You should have received a copy of the GNU General Public License | ||||||||||||||||||||
| 38 | along with VoiceXML::Client. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 3 | ▶ | use vars qw{ | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | $VERSION | ||||||||||||||||||||
| 50 | 3 | }; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 3 | $VERSION = $VoiceXML::Client::Item::VERSION; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | my $mode = $self->{'XMLElement'}->attribute('mode'); | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | ▶ | return undef unless (defined $mode); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | ▶ | unless ($mode eq 'dtmf') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | { | ||||||||||||||||||||
| 66 | 0 | warn "Only DTMF mode grammars currently supported"; | |||||||||||||||||||
| 67 | 0 | return undef; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | $self->{'mode'} = $mode; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | ▶ | $self->{'id'} = ($self->{'XMLElement'}->attribute('id') || int(rand(999999)) . time()); | ||||||||||||||||||
|
Condition0%0/3
$self->{'XMLElement'}->attribute('id') || int(rand 999999) . time
MC/DC0%0/2
$self->{'XMLElement'}->attribute('id') || int(rand 999999) . time
$self->{'XMLElement'}->attribute('id')
int(rand 999999) . time
Truth table0%0/3
A || B
A= $self->{'XMLElement'}->attribute('id')B= int(rand 999999) . time
| |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | $self->{'rules'} = {}; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | return 1; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | sub registerRule { | ||||||||||||||||||
|
Subroutine
registerRule: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 81 | 0 | my $self = shift; | |||||||||||||||||||
| 82 | 0 | my $id = shift; | |||||||||||||||||||
| 83 | 0 | ▶ | my $rule = shift || return; | ||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | $self->{'rules'}->{$id} = $rule; | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | sub isValidInput { | ||||||||||||||||||
|
Subroutine
isValidInput: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||
| 90 | 0 | ▶ | my $input = shift || ''; | ||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | warn "CHECKING GRAMMAR $self->{'id'}"; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | my $testcount = 0; | |||||||||||||||||||
| 95 | 0 | ▶ | while (my ($rid, $rule) = each %{$self->{'rules'}}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | { | ||||||||||||||||||||
| 97 | 0 | $testcount++; | |||||||||||||||||||
| 98 | 0 | ▶ | return 1 if ($rule->isValidInput($input)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | return 0 if ($testcount); # failed all rules | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | # no rules set... always good I say. | ||||||||||||||||||||
| 104 | 0 | return 1; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | ▶ | sub execute { | ||||||||||||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||
| 110 | 0 | my $handle = shift; | |||||||||||||||||||
| 111 | 0 | my $optParams = shift; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 0 | my $parentForm = $self->getParentForm(); | |||||||||||||||||||
| 115 | 0 | $parentForm->registerGrammar($self->{'id'}, $self); | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | # skip over kids... | ||||||||||||||||||||
| 118 | 0 | return $VoiceXML::Client::Flow::Directive{'CONTINUE'}; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 3 | 1; | |||||||||||||||||||