blib/lib/WAIT/Client.pm

filter: Statementstmt 27.4% 31 / 113 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 31.0% 9 / 29 Podpod 0.0% 0 / 6 totaltotal 19.6% 40 / 204 CC 28 SCAR 28.1
CC
28
Cov
19%
command
56.0
new
30.0
search
20.0
CRAP 16.6
« blib/lib/CPAN/WAIT.pm ↑ Summary /home/cpancover/.cpan/CPAN/MyConfig.pm »
1 #!/usr/bin/perl
2 # -*- Mode: Perl -*-
3 # $Basename: Client.pm $
4 # $Revision: 1.3 $
5 # Author : Ulrich Pfeifer
6 # Created On : Fri Jan 31 10:49:37 1997
7 # Last Modified By: Ulrich Pfeifer
8 # Last Modified On: Mon Aug 11 17:06:51 1997
9 # Language : CPerl
10 # Update Count : 88
11 # Status : Unknown, Use with caution!
12 #
13 # (C) Copyright 1997, Ulrich Pfeifer, all rights reserved.
14 #
15 #
16  
17 package WAIT::Client;
18 1 ▶use Net::NNTP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Net::Cmd qw(CMD_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 @ISA = qw(Net::NNTP);
25  
26 sub search
27 0 ▶{
Subroutine search: not called CC=2 SCAR=17.9
Pod undocumented
28 0 my $wait = shift;
29
30 0 ▶ $wait->_SEARCH(@_)
Branch: 1 branch
BranchTrueFalseTotal
$wait->_SEARCH(@_) ? : 0 0 0
31 ? $wait->read_until_dot()
32 : undef;
33 }
34  
35 sub info
36 0 ▶{
Subroutine info: not called CC=3 SCAR=24.8
Pod undocumented
37 0 ▶ @_ == 2 or croak 'usage: $wait->info( HIT-NUMBER )';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$wait->info( HIT-NUMBER )") 0 0 0
38 0 my $wait = shift;
39
40 0 ▶ $wait->_INFO(@_)
Branch: 1 branch
BranchTrueFalseTotal
$wait->_INFO(@_) ? : 0 0 0
41 ? $wait->read_until_dot()
42 : undef;
43 }
44  
45 sub get
46 0 ▶{
Subroutine get: not called CC=3 SCAR=24.8
Pod undocumented
47 0 ▶ @_ == 2 or croak 'usage: $wait->info( HIT-NUMBER )';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$wait->info( HIT-NUMBER )") 0 0 0
48 0 my $wait = shift;
49
50 0 ▶ $wait->_GET(@_)
Branch: 1 branch
BranchTrueFalseTotal
$wait->_GET(@_) ? : 0 0 0
51 ? $wait->read_until_dot()
52 : undef;
53 }
54  
55 sub database
56 0 ▶{
Subroutine database: not called CC=2 SCAR=17.9
Pod undocumented
57 0 ▶ @_ == 2 or croak 'usage: $wait->database( DBNAME )';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$wait->database( DBNAME )") 0 0 0
58 0 my $wait = shift;
59
60 0 $wait->_DATABASE(@_);
61 }
62  
63 sub table
64 0 ▶{
Subroutine table: not called CC=2 SCAR=17.9
Pod undocumented
65 0 ▶ @_ == 2 or croak 'usage: $wait->table( TABLE )';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$wait->table( TABLE )") 0 0 0
66 0 my $wait = shift;
67
68 0 $wait->_TABLE(@_);
69 }
70  
71 sub hits
72 0 ▶{
Subroutine hits: not called CC=2 SCAR=17.9
Pod undocumented
73 0 ▶ @_ == 2 or croak 'usage: $wait->hits( NUM-MAX-HITS )';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$wait->hits( NUM-MAX-HITS )") 0 0 0
74 0 my $wait = shift;
75
76 0 $wait->_HITS(@_);
77 }
78  
79 0 ▶sub _SEARCH { shift->command('SEARCH', @_)->response == CMD_OK }
Subroutine _SEARCH: not called CC=1 SCAR=6.9
80 0 ▶sub _INFO { shift->command('INFO', @_)->response == CMD_OK }
Subroutine _INFO: not called CC=1 SCAR=6.9
81 0 ▶sub _GET { shift->command('GET', @_)->response == CMD_OK }
Subroutine _GET: not called CC=1 SCAR=6.9
82 0 ▶sub _DATABASE { shift->command('DATABASE', @_)->response == CMD_OK }
Subroutine _DATABASE: not called CC=1 SCAR=6.9
83 0 ▶sub _TABLE { shift->command('TABLE', @_)->response == CMD_OK }
Subroutine _TABLE: not called CC=1 SCAR=6.9
84 0 ▶sub _HITS { shift->command('HITS', @_)->response == CMD_OK }
Subroutine _HITS: not called CC=1 SCAR=6.9
85  
86 # The following is a real hack. Don't look at it ;-) It tries to
87 # emulate a stateful protocol over HTTP which is weird and slow.
88 package WAIT::Client::HTTP;
89 1 ▶use Net::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
91 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93 1 @ISA = qw(WAIT::Client);
94  
95 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
96 0 my $type = shift;
97 0 my $host = shift;
98 0 my %parm = @_;
99 0 my ($proxy, $port) = ($parm{Proxy} =~ m{^(?:http://)(\S+)(?::(\d+))});
100 0 ▶ $port = 80 unless $port;
Branch: 1 branch
BranchTrueFalseTotal
unless $port 0 0 0
101
102 my $self = {
103 proxy_host => $proxy,
104 proxy_port => $port,
105 wais_host => $host,
106 wais_port => $parm{Port},
107 0 ▶ timeout => $parm{Timeout}||120,
Condition0%0/2
$parm{'Timeout'} || 120
l!l
00
MC/DC0%0/1
$parm{'Timeout'} || 120
$parm{'Timeout'}
Truth table0%0/2
A
A= $parm{'Timeout'}
Aresult
11
00
108 };
109 0 bless $self, $type;
110  
111 0 my $con;
112 0 ▶ if ($con = $self->command('HELP') and $con->response == CMD_INFO) {
Branch: 1 branch
BranchTrueFalseTotal
if ($con = $self->command('HELP') and $con->response == 1) { } 0 0 0
Condition0%0/3
$con = $self->command("HELP") and $con->response == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$con = $self->command("HELP") and $con->response == 1
$con = $self->command("HELP") $con->response == 1
Truth table0%0/3
A and B
A= $con = $self->command("HELP")B= $con->response == 1
ABresult
0X0
100
111
113 0 return $self;
114 } else {
115 0 return;
116 }
117 }
118  
119 0 ▶sub command {
Subroutine command: not called CC=7 SCAR=40.3
120 0 my $self = shift;
121 my $con = # Constructor inherited from IO::Socket::INET
122 WAIT::Client::HTTP::Handle->new
123 (
124 PeerAddr => $self->{proxy_host},
125 PeerPort => $self->{proxy_port},
126 0 Proto => 'tcp',
127 );
128 0 ▶ return unless $con;
Branch: 1 branch
BranchTrueFalseTotal
unless $con 0 0 0
129  
130 0 ▶ $con->timeout($self->{timeout}) if defined $self->{timeout};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"timeout"} 0 0 0
131 0 my $cmd = join ' ', @_;
132
133 0 ▶ if ($self->{hits}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"hits"}) 0 0 0
134 0 $cmd = "HITS $self->{hits}:$cmd";
135 }
136 0 $cmd = "Command: $cmd";
137 0 $con->autoflush(1);
138
139 0 $con->printf("POST http://$self->{wais_host}:$self->{wais_port} ".
140 "HTTP/1.0\nContent-Length: %d\n\n$cmd",
141 length($cmd));
142
143 0 ▶ unless ($con->response == CMD_OK) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($con->response == 2) 0 0 0
144 0 warn "No greeting from server\n";
145 }
146 0 ▶ if ($self->{hits}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"hits"}) 0 0 0
147 0 ▶ unless ($con->response == CMD_OK) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($con->response == 2) 0 0 0
148 0 warn "Hits not aknowledged\n";
149 }
150 }
151 0 $self->{con} = $con;
152 0 $con;
153 }
154  
155 # We map here raw document id's to rank numbers and back for
156 # convenience. Besides that the following search(), info(), and get()
157 # are obsolete.
158  
159 sub search
160 0 ▶{
Subroutine search: not called CC=4 SCAR=30.0
161 0 my $wait = shift;
162
163 0 ▶ if ($wait->_SEARCH(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wait->_SEARCH(@_)) 0 0 0
164 0 my $r = $wait->read_until_dot();
165 0 my $i = 1;
166
167 0 delete $wait->{'map'};
168 0 for (@$r) {
169 0 ▶ if (s/^(\d+)/sprintf("%4d",$i)/e) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^(\d+)/sprintf "%4d", $i;/e) 0 0 0
170 0 $wait->{'map'}->[$i++] = $1;
171 }
172 }
173 0 return $r;
174 }
175 0 return undef;
176 }
177  
178 sub info
179 0 ▶{
Subroutine info: not called CC=4 SCAR=30.0
180 0 ▶ @_ == 2 or croak 'usage: $wait->info( HIT-NUMBER )';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$wait->info( HIT-NUMBER )") 0 0 0
181 0 my $wait = shift;
182 0 my $num = shift;
183  
184 0 ▶ unless ($wait->{'map'}->[$num]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($wait->{"map"}[$num]) 0 0 0
185 0 print "No such hit: $num\n";
186 0 return;
187 }
188 0 ▶ $wait->_INFO($wait->{'map'}->[$num])
Branch: 1 branch
BranchTrueFalseTotal
$wait->_INFO($wait->{'map'}[$num]) ? : 0 0 0
189 ? $wait->read_until_dot()
190 : undef;
191 }
192  
193 sub get
194 0 ▶{
Subroutine get: not called CC=4 SCAR=30.0
195 0 ▶ @_ == 2 or croak 'usage: $wait->info( HIT-NUMBER )';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$wait->info( HIT-NUMBER )") 0 0 0
196 0 my $wait = shift;
197 0 my $num = shift;
198  
199 0 ▶ unless ($wait->{'map'}->[$num]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($wait->{"map"}[$num]) 0 0 0
200 0 print "No such hit: $num\n";
201 0 return;
202 }
203 0 ▶ $wait->_GET($wait->{'map'}->[$num])
Branch: 1 branch
BranchTrueFalseTotal
$wait->_GET($wait->{'map'}[$num]) ? : 0 0 0
204 ? $wait->read_until_dot()
205 : undef;
206 }
207  
208 # We must store the hit count locally
209 0 ▶sub _HITS {
Subroutine _HITS: not called CC=1 SCAR=6.9
210 0 my $self = shift;
211 0 my $hits = shift;
212  
213 0 $self->{hits} = $hits;
214 0 ["Setting maximum hit count to $hits"];
215 }
216  
217 # We should use AUTOLOAD here. I know ;-)
218 0 ▶sub read_until_dot {shift->{con}->read_until_dot(@_)}
Subroutine read_until_dot: not called CC=1 SCAR=6.9
219 0 ▶sub message {shift->{con}->message(@_)}
Subroutine message: not called CC=1 SCAR=6.9
220  
221 package WAIT::Client::HTTP::Handle;
222 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
223  
224 1 @ISA = qw(Net::Cmd IO::Socket::INET);
225  
226  
227 1 1;
« blib/lib/CPAN/WAIT.pm ↑ Summary /home/cpancover/.cpan/CPAN/MyConfig.pm »