NAME
Net::Dict - client API for accessing dictionary servers (RFC 2229)
SYNOPSIS
use Net::Dict;
$dict = Net::Dict->new("some.host.name");
$h = $dict->define("word");
foreach $i (@{$h}) {
($db, $def) = @{$i};
. . .
}
DESCRIPTION
Net::Dict
is a class implementing a simple Dict client in Perl as described in RFC2229. It provides wrappers for a subset of the RFC2229 commands.
OVERVIEW
Quotation from RFC2229:
The Dictionary Server Protocol (DICT) is a TCP transaction based
query/response protocol that allows a client to access dictionary
definitions from a set of natural language dictionary databases.
CONSTRUCTOR
$dict = Net::Dict->new (HOST [,OPTIONS]);
This is the constructor for a new Net::Dict object. HOST
is the name of the remote host on which a Dict server is running.
If the HOST
value is an empty string, the default behavior is to try dict.org, alt0.dict.org, alt1.dict.org, and alt2.dict.org, in that order.
OPTIONS
are passed in a hash like fashion, using key and value pairs. Possible options are:
- ConfigFile
-
The path to the configuration file (see dict(1) for details on the format of the config. file). The config file entries override the default definitions (e.g. server name and port), but are overriden by an explicit definitions in the constructor.
- HTML
-
Give an output of 'match' and 'define' in HTML.
- Port
-
The port number to connect to on the remote machine for the Dict connection (a default port number is 2628, according to RFC2229).
- Client
-
The string to send as the CLIENT identifier. If not set, then a default identifier for Net::Dict is sent.
- Timeout
-
Set a timeout value (defaults to 120)
- Debug
-
debug level (see the debug method in Net::Cmd)
METHODS
Unless otherwise stated all methods return either a true or false value, with true meaning that the operation was a success. When a method states that it returns a value, failure will be returned as undef or an empty list.
- serverInfo()
-
returns a string, containing the information about the server.
- dbs()
-
returns a hash, containing an ID of the dictionary as a key and description as the value.
- dbInfo($dbname)
-
returns a string, containing description of the dictionary $dbname.
- setDicts(@dicts)
-
sets the set of dictionaries, that will be searched during the successive define() calls. Defaults to '*'. No existance checks are performed by this interface, so you'd better make sure the dictionaries you specify are on the server (e.g. by calling dbs()).
- strats()
-
returns an array, containing an ID of a matching strategy as a key and a verbose description as a value.
- define($word [, @dbs])
-
returns a reference to an array, whose members are lists, consisting of two elements: the dictionary name and the definition. If no dictionaries are specified, those set by setDicts() are used.
- match($word, $strategy [, @dbs])
-
same as define(), but a matching using the specified strategies is performed. Return array of lists, consisting of dictionary - match pairs.
- dbTitle($dbname)
-
Returns the title string for the specified dictionary. This is the same string returned by the
dbs()
method for all databases.
UNIMPLEMENTED
The following RFC2229 commands have not been implemented:
- authentication
-
The authentication protocol isn't currently implemented.
REPORTING BUGS
When reporting bugs/problems please include as much information as possible. It may be difficult for me to reproduce the problem as almost every setup is different.
A small script which yields the problem will probably be of help. It would also be useful if this script was run with the extra options Debug => 1
passed to the constructor, and the output sent with the bug report. If you cannot include a small script then please include a Debug trace from a run of your program which does yield the problem.
EXAMPLES
The examples directory of the Net-Dict distribution includes simple.pl, which illustrates basic use of the module.
AUTHOR
Net::Dict was written by Dmitry Rubinstein <dimrub@wisdom.weizmann.ac.il>, using Net::FTP and Net::SMTP as a pattern and a model for imitation.
The module is now maintained by Neil Bowers <neilb@cre.canon.co.uk>
SEE ALSO
dict(1), dictd(8), RFC 2229 http://www.cis.ohio-state.edu/htbin/rfc/rfc2229.html http://www.dict.org/
COPYRIGHT
Copyright (C) 2001 Canon Research Centre Europe, Ltd.
Copyright (c) 1998 Dmitry Rubinstein. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.