| 1 | # | ||||||||||||||||||||||||||||
| 2 | # Net::Dict.pm | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # Copyright (C) 2001-2003 Neil Bowers <neil@bowers.com> | ||||||||||||||||||||||||||||
| 5 | # Copyright (c) 1998 Dmitry Rubinstein <dimrub@wisdom.weizmann.ac.il>. | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # All rights reserved. This program is free software; you can | ||||||||||||||||||||||||||||
| 8 | # redistribute it and/or modify it under the same terms as Perl | ||||||||||||||||||||||||||||
| 9 | # itself. | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Net::Dict; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Net::Cmd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 5 | our $VERSION = '2.22'; | |||||||||||||||||||||||||||
| 21 | 5 | our $debug; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 24 | # Default values for arguments to new(). We also use this to | ||||||||||||||||||||||||||||
| 25 | # determine valid argument names - if it's not a key of this hash, | ||||||||||||||||||||||||||||
| 26 | # then it's not a valid argument. | ||||||||||||||||||||||||||||
| 27 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 28 | 5 | my %ARG_DEFAULT = | |||||||||||||||||||||||||||
| 29 | ( | ||||||||||||||||||||||||||||
| 30 | Port => 2628, | ||||||||||||||||||||||||||||
| 31 | Timeout => 120, | ||||||||||||||||||||||||||||
| 32 | Debug => 0, | ||||||||||||||||||||||||||||
| 33 | Client => "Net::Dict v$VERSION", | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 5 | our @ISA = qw(Net::Cmd IO::Socket::INET); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #======================================================================= | ||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||
| 40 | # new() | ||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||
| 42 | # constructor - open connection to host, get a list of databases, | ||||||||||||||||||||||||||||
| 43 | # and send CLIENT identification command. | ||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||
| 45 | #======================================================================= | ||||||||||||||||||||||||||||
| 46 | sub new | ||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 9 | ▶ | @_ > 1 or croak 'usage: Net::Dict->new() takes at least a HOST name'; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 8 | my $class = shift; | |||||||||||||||||||||||||||
| 50 | 8 | my $host = shift; | |||||||||||||||||||||||||||
| 51 | 8 | ▶ | int(@_) % 2 == 0 or croak 'Net::Dict->new(): odd number of arguments'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 7 | my %inargs = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 7 | my $self; | |||||||||||||||||||||||||||
| 55 | my $argref; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 7 | ▶ | return undef unless defined $host; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 61 | # Process arguments, setting defaults if needed | ||||||||||||||||||||||||||||
| 62 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 63 | 6 | $argref = {}; | |||||||||||||||||||||||||||
| 64 | 6 | foreach my $arg (keys %ARG_DEFAULT) { | |||||||||||||||||||||||||||
| 65 | $argref->{$arg} = exists $inargs{$arg} | ||||||||||||||||||||||||||||
| 66 | ? $inargs{$arg} | ||||||||||||||||||||||||||||
| 67 | 24 | ▶ | : $ARG_DEFAULT{$arg}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 24 | delete $inargs{$arg}; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 6 | ▶ | if (keys(%inargs) > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 1 | croak "Net::Dict->new(): unknown argument - ", | |||||||||||||||||||||||||||
| 73 | join(', ', keys %inargs); | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 77 | # Make the connection | ||||||||||||||||||||||||||||
| 78 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 79 | $self = $class->SUPER::new(PeerAddr => $host, | ||||||||||||||||||||||||||||
| 80 | PeerPort => $argref->{Port}, | ||||||||||||||||||||||||||||
| 81 | Proto => 'tcp', | ||||||||||||||||||||||||||||
| 82 | Timeout => $argref->{Timeout} | ||||||||||||||||||||||||||||
| 83 | 5 | ); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 5 | ▶ | return undef unless defined $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 4 | ${*$self}{'net_dict_host'} = $host; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 4 | $self->autoflush(1); | |||||||||||||||||||||||||||
| 90 | 4 | $self->debug($argref->{Debug}); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 4 | ▶ | if ($self->response() != CMD_OK) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | $self->close(); | |||||||||||||||||||||||||||
| 94 | 0 | return undef; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # parse the initial 220 response | ||||||||||||||||||||||||||||
| 98 | 4 | $self->_parse_banner($self->message); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 101 | # Send the CLIENT command which identifies the connecting client | ||||||||||||||||||||||||||||
| 102 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 103 | 4 | $self->_CLIENT($argref->{Client}); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 106 | # The default - search ALL dictionaries | ||||||||||||||||||||||||||||
| 107 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 108 | 4 | $self->setDicts('*'); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 4 | return $self; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | sub dbs | ||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 2 | ▶ | @_ == 1 or croak 'usage: $dict->dbs() - takes no arguments'; | ||||||||||||||||||||||||||
|
Subroutine
dbs: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | $self->_get_database_list(); | |||||||||||||||||||||||||||
| 119 | 1 | return %{${*$self}{'net_dict_dbs'}}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub setDicts | ||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||
| 124 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
setDicts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 8 | @{${*$self}{'net_dict_userdbs'}} = @_; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | sub serverInfo | ||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||
| 131 | 1 | ▶ | @_ == 1 or croak 'usage: $dict->serverInfo()'; | ||||||||||||||||||||||||||
|
Subroutine
serverInfo: called CC=3 SCAR=11.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 1 | ▶ | return 0 unless $self->_SHOW_SERVER(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | my $info = join('', @{$self->read_until_dot}); | |||||||||||||||||||||||||||
| 137 | 1 | $self->getline(); | |||||||||||||||||||||||||||
| 138 | 1 | $info; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | sub dbInfo | ||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||
| 143 | 4 | ▶ | @_ == 2 or croak 'usage: $dict->dbInfo($dbname) - one argument only'; | ||||||||||||||||||||||||||
|
Subroutine
dbInfo: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 2 | ▶ | if ($self->_SHOW_INFO(@_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 1 | return join('', @{$self->read_until_dot()}); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||
| 150 | 1 | return undef; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | sub dbTitle | ||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||
| 156 | 5 | ▶ | @_ == 2 or croak 'dbTitle() method expects one argument - DB name'; | ||||||||||||||||||||||||||
|
Subroutine
dbTitle: called CC=4 SCAR=13.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 158 | 3 | my $dbname = shift; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 3 | $self->_get_database_list(); | |||||||||||||||||||||||||||
| 162 | 3 | ▶ | if (exists ${${*$self}{'net_dict_dbs'}}{$dbname}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 1 | return ${${*$self}{'net_dict_dbs'}}{$dbname}; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | else { | ||||||||||||||||||||||||||||
| 166 | 2 | ▶ | carp 'dbTitle(): unknown database name' if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 2 | return undef; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | sub strategies | ||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||
| 173 | 2 | ▶ | @_ == 1 or croak 'usage: $dict->strategies()'; | ||||||||||||||||||||||||||
|
Subroutine
strategies: called CC=4 SCAR=14.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 2 | ▶ | return 0 unless $self->_SHOW_STRAT(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 2 | my (%strats, $name, $desc); | |||||||||||||||||||||||||||
| 179 | 2 | foreach (@{$self->read_until_dot()}) { | |||||||||||||||||||||||||||
| 180 | 24 | ($name, $desc) = (split /\s/, $_, 2); | |||||||||||||||||||||||||||
| 181 | 24 | chomp $desc; | |||||||||||||||||||||||||||
| 182 | 24 | $strats{$name} = _unquote($desc); | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | 2 | $self->getline(); | |||||||||||||||||||||||||||
| 185 | 2 | %strats; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | sub define | ||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||
| 190 | 14 | ▶ | @_ >= 2 or croak 'usage: $dict->define($word [, @dbs]) - takes at least one argument'; | ||||||||||||||||||||||||||
|
Subroutine
define: called CC=9 SCAR=22.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 192 | 13 | my $word = shift; | |||||||||||||||||||||||||||
| 193 | 13 | ▶ | my @dbs = (@_ > 0) ? @_ : @{${*$self}{'net_dict_userdbs'}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 13 | ▶ | croak 'select some dictionaries with setDicts or supply as argument to define' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | unless @dbs; | ||||||||||||||||||||||||||||
| 196 | 12 | my($db, @defs); | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 200 | # check whether we got an empty word | ||||||||||||||||||||||||||||
| 201 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 202 | 12 | ▶ | if (!defined($word) || $word eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $word or $word eq ""
MC/DC100%2/2
not defined $word or $word eq ""
not defined $word
$word eq ""
Truth table100%3/3
not(A) or B
A= not defined $wordB= $word eq ""
| |||||||||||||||||||||||||||||
| 203 | 2 | carp "empty word passed to define() method"; | |||||||||||||||||||||||||||
| 204 | 2 | return undef; | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 10 | foreach $db (@dbs) { | |||||||||||||||||||||||||||
| 208 | 10 | ▶ | next unless $self->_DEFINE($db, $word); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 8 | my ($defNum) = ($self->message =~ /^\d{3} (\d+) /); | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 8 | foreach (0..$defNum-1) { | |||||||||||||||||||||||||||
| 213 | 15 | my ($d) = ($self->getline =~ /^\d{3} ".*" ([-\w]+) /); | |||||||||||||||||||||||||||
| 214 | 15 | my ($def) = join '', @{$self->read_until_dot}; | |||||||||||||||||||||||||||
| 215 | 15 | push @defs, [$d, $def]; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | 8 | $self->getline(); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 10 | \@defs; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | sub match | ||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||
| 224 | 11 | ▶ | @_ >= 3 or croak 'usage: $self->match($word, $strat [, @dbs]) - takes at least two arguments'; | ||||||||||||||||||||||||||
|
Subroutine
match: called CC=9 SCAR=22.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 226 | 9 | my $word = shift; | |||||||||||||||||||||||||||
| 227 | 9 | my $strat = shift; | |||||||||||||||||||||||||||
| 228 | 9 | ▶ | my @dbs = (@_ > 0) ? @_ : @{${*$self}{'net_dict_userdbs'}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 9 | ▶ | croak 'define some dictionaries by setDicts or supply as argument to define' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | unless @dbs; | ||||||||||||||||||||||||||||
| 231 | 9 | my ($db, @matches); | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 234 | # check whether we got an empty pattern | ||||||||||||||||||||||||||||
| 235 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 236 | 9 | ▶ | if (!defined($word) || $word eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $word or $word eq ""
MC/DC100%2/2
not defined $word or $word eq ""
not defined $word
$word eq ""
Truth table100%3/3
not(A) or B
A= not defined $wordB= $word eq ""
| |||||||||||||||||||||||||||||
| 237 | 2 | carp "empty pattern passed to match() method"; | |||||||||||||||||||||||||||
| 238 | 2 | return undef; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 7 | foreach $db (@dbs) { | |||||||||||||||||||||||||||
| 242 | 7 | ▶ | next unless $self->_MATCH($db, $strat, $word); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 7 | my ($db, $w); | |||||||||||||||||||||||||||
| 245 | 7 | foreach (@{$self->read_until_dot}) { | |||||||||||||||||||||||||||
| 246 | 218 | ($db, $w) = split /\s/, $_, 2; | |||||||||||||||||||||||||||
| 247 | 218 | chomp $w; | |||||||||||||||||||||||||||
| 248 | 218 | push @matches, [$db, _unquote($w)]; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | 7 | $self->getline(); | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | 7 | \@matches; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | sub auth | ||||||||||||||||||||||||||||
| 256 | { | ||||||||||||||||||||||||||||
| 257 | 0 | ▶ | @_ == 3 or croak 'usage: $dict->auth() - takes two arguments'; | ||||||||||||||||||||||||||
|
Subroutine
auth: not called CC=4 SCAR=30.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 259 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 260 | 0 | my $pass_phrase = shift; | |||||||||||||||||||||||||||
| 261 | 0 | my $auth_string; | |||||||||||||||||||||||||||
| 262 | my $string; | ||||||||||||||||||||||||||||
| 263 | 0 | my $ctx; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | require Digest::MD5; | |||||||||||||||||||||||||||
| 267 | 0 | $string = $self->msg_id().$pass_phrase; | |||||||||||||||||||||||||||
| 268 | 0 | $auth_string = Digest::MD5::md5_hex($string); | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if ($self->_AUTH($user, $auth_string)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | #--------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 272 | # clear the cache of database names | ||||||||||||||||||||||||||||
| 273 | # next time a method needs them, this will cause us to go | ||||||||||||||||||||||||||||
| 274 | # back to the server, and thus pick up any AUTH-restricted DBs | ||||||||||||||||||||||||||||
| 275 | #--------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 276 | 0 | delete ${*$self}{'net_dict_dbs'}; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | else { | ||||||||||||||||||||||||||||
| 279 | 0 | ▶ | carp "auth() failed with error code ".$self->code() if $self->debug(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 0 | return; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | sub status | ||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||
| 286 | 2 | ▶ | @_ == 1 or croak 'usage: $dict->status() - takes no arguments'; | ||||||||||||||||||||||||||
|
Subroutine
status: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 288 | 1 | my $message; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 1 | ▶ | $self->_STATUS() || return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 1 | chomp($message = $self->message); | |||||||||||||||||||||||||||
| 293 | 1 | $message =~ s/^\d{3} //; | |||||||||||||||||||||||||||
| 294 | 1 | return $message; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | sub capabilities | ||||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||
| 299 | 5 | ▶ | @_ == 1 or croak 'usage: $dict->capabilities() - takes no arguments'; | ||||||||||||||||||||||||||
|
Subroutine
capabilities: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 4 | return @{ ${*$self}{'net_dict_capabilities'} }; | |||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | sub has_capability | ||||||||||||||||||||||||||||
| 307 | { | ||||||||||||||||||||||||||||
| 308 | 5 | ▶ | @_ == 2 or croak 'usage: $dict->has_capability() - takes one argument'; | ||||||||||||||||||||||||||
|
Subroutine
has_capability: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 310 | 3 | my $cap = shift; | |||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 3 | return grep(lc($cap) eq $_, $self->capabilities()); | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | sub msg_id | ||||||||||||||||||||||||||||
| 317 | { | ||||||||||||||||||||||||||||
| 318 | 2 | ▶ | @_ == 1 or croak 'usage: $dict->msg_id() - takes no arguments'; | ||||||||||||||||||||||||||
|
Subroutine
msg_id: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 1 | return ${*$self}{'net_dict_msgid'}; | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 10 | ▶ | sub _DEFINE { shift->command('DEFINE', map { '"'.$_.'"' } @_)->response() == CMD_INFO } | ||||||||||||||||||||||||||
|
Subroutine
_DEFINE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 327 | 7 | ▶ | sub _MATCH { shift->command('MATCH', map { '"'.$_.'"' } @_)->response() == CMD_INFO } | ||||||||||||||||||||||||||
|
Subroutine
_MATCH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 328 | 1 | ▶ | sub _SHOW_DB { shift->command('SHOW DB')->response() == CMD_INFO } | ||||||||||||||||||||||||||
|
Subroutine
_SHOW_DB: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 329 | 2 | ▶ | sub _SHOW_STRAT { shift->command('SHOW STRAT')->response() == CMD_INFO } | ||||||||||||||||||||||||||
|
Subroutine
_SHOW_STRAT: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 330 | 2 | ▶ | sub _SHOW_INFO { shift->command('SHOW INFO', @_)->response() == CMD_INFO } | ||||||||||||||||||||||||||
|
Subroutine
_SHOW_INFO: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 331 | 1 | ▶ | sub _SHOW_SERVER { shift->command('SHOW SERVER')->response() == CMD_INFO } | ||||||||||||||||||||||||||
|
Subroutine
_SHOW_SERVER: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 332 | 4 | ▶ | sub _CLIENT { shift->command('CLIENT', @_)->response() == CMD_OK } | ||||||||||||||||||||||||||
|
Subroutine
_CLIENT: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 333 | 1 | ▶ | sub _STATUS { shift->command('STATUS')->response() == CMD_OK } | ||||||||||||||||||||||||||
|
Subroutine
_STATUS: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 334 | 0 | ▶ | sub _HELP { shift->command('HELP')->response() == CMD_INFO } | ||||||||||||||||||||||||||
|
Subroutine
_HELP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 335 | 1 | ▶ | sub _QUIT { shift->command('QUIT')->response() == CMD_OK } | ||||||||||||||||||||||||||
|
Subroutine
_QUIT: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 336 | 0 | ▶ | sub _OPTION_MIME { shift->command('OPTION MIME')->response() == CMD_OK } | ||||||||||||||||||||||||||
|
Subroutine
_OPTION_MIME: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub _AUTH { shift->command('AUTH', @_)->response() == CMD_OK } | ||||||||||||||||||||||||||
|
Subroutine
_AUTH: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 338 | 0 | ▶ | sub _SASLAUTH { shift->command('SASLAUTH', @_)->response() == CMD_OK } | ||||||||||||||||||||||||||
|
Subroutine
_SASLAUTH: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 339 | 0 | ▶ | sub _SASLRESP { shift->command('SASLRESP', @_)->response() == CMD_OK } | ||||||||||||||||||||||||||
|
Subroutine
_SASLRESP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | sub quit | ||||||||||||||||||||||||||||
| 342 | { | ||||||||||||||||||||||||||||
| 343 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
quit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 1 | $self->_QUIT; | |||||||||||||||||||||||||||
| 346 | 1 | $self->close; | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | sub DESTROY | ||||||||||||||||||||||||||||
| 350 | { | ||||||||||||||||||||||||||||
| 351 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 2 | ▶ | if (defined fileno($self)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | 1 | $self->quit; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | sub response | ||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||
| 360 | 33 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
response: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 361 | 33 | ▶ | my $str = $self->getline() || return undef; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->getline || (return undef)
MC/DC0%0/1
$self->getline || (return undef)
$self->getline
Truth table50%1/2
A
A= $self->getline
| |||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 33 | ▶ | if ($self->debug) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 365 | 0 | $self->debug_print(0,$str); | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 33 | my($code) = ($str =~ /^(\d+) /); | |||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 33 | ${*$self}{'net_cmd_resp'} = [ $str ]; | |||||||||||||||||||||||||||
| 371 | 33 | ${*$self}{'net_cmd_code'} = $code; | |||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 33 | substr($code,0,1); | |||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | #======================================================================= | ||||||||||||||||||||||||||||
| 377 | # | ||||||||||||||||||||||||||||
| 378 | # _unquote | ||||||||||||||||||||||||||||
| 379 | # | ||||||||||||||||||||||||||||
| 380 | # Private function used to remove quotation marks from around | ||||||||||||||||||||||||||||
| 381 | # a string. | ||||||||||||||||||||||||||||
| 382 | # | ||||||||||||||||||||||||||||
| 383 | #======================================================================= | ||||||||||||||||||||||||||||
| 384 | sub _unquote | ||||||||||||||||||||||||||||
| 385 | { | ||||||||||||||||||||||||||||
| 386 | 516 | ▶ | my $string = shift; | ||||||||||||||||||||||||||
|
Subroutine
_unquote: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 516 | ▶ | if ($string =~ /^"/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | 516 | $string =~ s/^"//; | |||||||||||||||||||||||||||
| 391 | 516 | $string =~ s/"$//; | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | 516 | return $string; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | #======================================================================= | ||||||||||||||||||||||||||||
| 397 | # | ||||||||||||||||||||||||||||
| 398 | # _parse_banner | ||||||||||||||||||||||||||||
| 399 | # | ||||||||||||||||||||||||||||
| 400 | # Parse the initial response banner the server sends when we connect. | ||||||||||||||||||||||||||||
| 401 | # Hoping for: | ||||||||||||||||||||||||||||
| 402 | # 220 blah blah <auth.mime> <msgid> | ||||||||||||||||||||||||||||
| 403 | # The <auth.mime> string gives a list of supported extensions. | ||||||||||||||||||||||||||||
| 404 | # The last bit is a msg-id, which identifies this connection, | ||||||||||||||||||||||||||||
| 405 | # and is used in authentication, for example. | ||||||||||||||||||||||||||||
| 406 | # | ||||||||||||||||||||||||||||
| 407 | #======================================================================= | ||||||||||||||||||||||||||||
| 408 | sub _parse_banner | ||||||||||||||||||||||||||||
| 409 | { | ||||||||||||||||||||||||||||
| 410 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_parse_banner: called CC=4 SCAR=14.4
| |||||||||||||||||||||||||||||
| 411 | 4 | my $banner = shift; | |||||||||||||||||||||||||||
| 412 | 4 | my ($code, $capstring, $msgid); | |||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 4 | ${*$self}{'net_dict_banner'} = $banner; | |||||||||||||||||||||||||||
| 416 | 4 | ${*$self}{'net_dict_capabilities'} = []; | |||||||||||||||||||||||||||
| 417 | 4 | ▶ | if ($banner =~ /^(\d{3}) (.*) (<[^<>]*>)?\s+(<[^<>]+>)\s*$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | 4 | ${*$self}{'net_dict_msgid'} = $4; | |||||||||||||||||||||||||||
| 419 | 4 | ($capstring = $3) =~ s/[<>]//g; | |||||||||||||||||||||||||||
| 420 | 4 | ▶ | if (length($capstring) > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | 4 | ${*$self}{'net_dict_capabilities'} = [split(/\./, $capstring)]; | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | else { | ||||||||||||||||||||||||||||
| 425 | 0 | ▶ | carp "unexpected format for welcome banner on connection:\n", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | $banner if $self->debug; | ||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | #======================================================================= | ||||||||||||||||||||||||||||
| 431 | # | ||||||||||||||||||||||||||||
| 432 | # _get_database_list | ||||||||||||||||||||||||||||
| 433 | # | ||||||||||||||||||||||||||||
| 434 | # Get the list of databases on the remote server. | ||||||||||||||||||||||||||||
| 435 | # We cache them in the instance data object, so that dbTitle() | ||||||||||||||||||||||||||||
| 436 | # and databases() don't have to go to the server every time. | ||||||||||||||||||||||||||||
| 437 | # | ||||||||||||||||||||||||||||
| 438 | # We check to see whether we've already got the databases first, | ||||||||||||||||||||||||||||
| 439 | # and do nothing if so. This means that this private method | ||||||||||||||||||||||||||||
| 440 | # can just be invoked in the public methods. | ||||||||||||||||||||||||||||
| 441 | # | ||||||||||||||||||||||||||||
| 442 | #======================================================================= | ||||||||||||||||||||||||||||
| 443 | sub _get_database_list | ||||||||||||||||||||||||||||
| 444 | { | ||||||||||||||||||||||||||||
| 445 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_get_database_list: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 4 | ▶ | return if exists ${*$self}{'net_dict_dbs'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 1 | ▶ | if ($self->_SHOW_DB) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 1 | my ($dbNum) = ($self->message =~ /^\d{3} (\d+)/); | |||||||||||||||||||||||||||
| 452 | 1 | my ($name, $descr); | |||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | 1 | foreach (0..$dbNum-1) { | |||||||||||||||||||||||||||
| 455 | 274 | ($name, $descr) = (split /\s/, $self->getline, 2); | |||||||||||||||||||||||||||
| 456 | 274 | chomp $descr; | |||||||||||||||||||||||||||
| 457 | 274 | ${${*$self}{'net_dict_dbs'}}{$name} = _unquote($descr); | |||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | # Is there a way to do it right? Reading the dot line and the | ||||||||||||||||||||||||||||
| 461 | # status line afterwards? Maybe I should use read_until_dot? | ||||||||||||||||||||||||||||
| 462 | 1 | $self->getline(); | |||||||||||||||||||||||||||
| 463 | 1 | $self->getline(); | |||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 468 | # Method aliases for backwards compatibility | ||||||||||||||||||||||||||||
| 469 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 470 | 5 | *strats = \&strategies; | |||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 5 | 1; | |||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||