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