| 1 | package Festival::Client; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Perl interface to the Festival server | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # The basis for this code came from the festival_client.pl program by | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Kevin A. Lenzo (lenzo@cs.cmu.edu) which comes with the Festival | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # distribution. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Last updated by gossamer on Thu May 21 16:11:24 EST 1998 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Fcntl; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | require 'dumpvar.pl'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | @EXPORT = qw( Default_Client_PORT ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | @EXPORT_OK = qw(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | $VERSION = "1.0"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | Festival::Client - Communicate with a Festival server | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | use Festival::Client; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | $Festival = Festival::Client->New("my.festival.server"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | $Festival->say("Something to say"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | C<Festival> is a class implementing a simple Festival client in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | Perl. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Some constants # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my $Default_Festival_Port = 1314; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | my $Client_Info = "0.01"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Functions under here are member functions # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | =item new ( [ HOST [, PORT ] ] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | This is the constructor for a new Festival object. C<HOST> is the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | name of the remote host to which a Festival connection is required. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | C<PORT> is the Festival port to connect to, it defaults to the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | standard port 1314 if nothing else is found. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | The constructor returns the open socket, or C<undef> if an error has | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | been encountered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=32.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my $prototype = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | my $host = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my $port = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | my $class = ref($prototype) || $prototype; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $prototype || $prototype
MC/DC0%0/2
ref $prototype || $prototype
ref $prototype
$prototype
Truth table33%1/3
A || B
A= ref $prototypeB= $prototype
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | warn "new\n" if $DEBUG > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | $self->{"host"} = $host || $ENV{HWHOST} || $ENV{HGHOST} || 'localhost'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition37%3/8
$host || $ENV{'HWHOST'} || $ENV{'HGHOST'} || 'localhost'
$host or $ENV{"HWHOST"} or $ENV{"HGHOST"}
$host or $ENV{"HWHOST"}
MC/DC0%0/3
$host || $ENV{'HWHOST'} || $ENV{'HGHOST'} || 'localhost'
$host
$ENV{"HWHOST"}
$ENV{"HGHOST"}
Truth table25%1/4
A or B or C
A= $hostB= $ENV{"HWHOST"}C= $ENV{"HGHOST"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | $self->{"port"} = $port || $ENV{HWPORT} || $ENV{HGPORT} || $Default_Festival_Port; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%3/9
$port || $ENV{'HWPORT'} || $ENV{'HGPORT'} || $Default_Festival_Port
$port or $ENV{"HWPORT"} or $ENV{"HGPORT"}
$port or $ENV{"HWPORT"}
MC/DC0%0/4
$port || $ENV{'HWPORT'} || $ENV{'HGPORT'} || $Default_Festival_Port
$port
$ENV{"HWPORT"}
$ENV{"HGPORT"}
$Default_Festival_Port
Truth table20%1/5
A or B or C || D
A= $portB= $ENV{"HWPORT"}C= $ENV{"HGPORT"}D= $Default_Festival_Port
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Resolve things and open the connection | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Deal with a port specified from /etc/services list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | if ($self->{"port"} =~ /\D/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $self->{"port"} = getservbyname($self->{"port"}, 'tcp'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | print "Addr: " . $self->{"host"} . ", Port: " . $self->{"port"} . "\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | $self->{"socket"} = new IO::Socket::INET ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | Proto => "tcp", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | PeerAddr => $self->{"host"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | PeerPort => $self->{"port"}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | #croak "new: connect socket: $!" unless $self->{"socket"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | ▶ | return 0 unless $self->{"socket"}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # destructor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | warn "DESTROY\n" if $DEBUG > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | shutdown($self->{"socket"}, 2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | close($self->{"socket"}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =head1 SAY ( TEXT ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | The obvious. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub say { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
say: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | warn "say \"$text\"\n" if $DEBUG > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $buffer = "(SayText \"$text\")\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if (!defined(syswrite($self->{"socket"}, $buffer, length($buffer)))) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | warn "syswrite: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | Bek Oberin <gossamer@tertius.net.au> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | Copyright (c) 1998 Bek Oberin. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # End code. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||