Net::Cmd - Network Command class |
Net::Cmd - Network Command class (as used by FTP, SMTP etc)
use Net::Cmd;
@ISA = qw(Net::Cmd);
Net::Cmd
is a collection of methods that can be inherited by a sub-class
of IO::Socket::INET
. These methods implement the functionality required for a
command based protocol, for example FTP and SMTP.
If your sub-class does not also derive from IO::Socket::INET
or similar (e.g.
IO::Socket::IP
, IO::Socket::INET6
or IO::Socket::SSL
) then you must
provide the following methods by other means yourself: close()
and
timeout()
.
These methods provide a user interface to the Net::Cmd
object.
VALUE
is not given
then the current state is returned. Otherwise the state is changed to
VALUE
and the previous state returned.
Different packages may implement different levels of debug but a non-zero value results in copies of all commands and responses also being sent to STDERR.
If VALUE
is undef
then the debug level will be set to the default
debug level for the class.
This method can also be called as a static method to set/get the default debug level for a given class.
CMD_PENDING
is returned.
DATA
may be an array or a reference to an array.
The DATA
passed in must be encoded by the caller to octets of whatever
encoding is required, e.g. by using the Encode module's encode()
function.
dataend
calls response
and
returns true if response
returns CMD_OK.
These methods are not intended to be called by the user, but used or
over-ridden by a sub-class of Net::Cmd
DIR
denotes the direction true being
data being sent to the server. Calls debug_text
before printing to
STDERR.
This is primarily meant for the use of modules such as FTP where passwords are sent, but we do not want to display them in the debugging information.
Returns undef upon failure.
response
as a method with one argument. It should
return an array of 2 values, the 3-digit status code and a flag which is true
when this is part of a multi-line response and this line is not the last.
NOTE: If you do use this method for any reason, please remember to add
some debug_print
calls into your method.
DATA
is a scalar.
As with datasend()
, the DATA
passed in must be encoded by the caller
to octets of whatever encoding is required, e.g. by using the Encode module's
encode()
function.
Returns a reference to a list containing the lines, or undef upon failure.
read()
or <>. The
filehandle will return EOF when the final dot is encountered.
Similarly, you may write to the filehandle in order to send data to
the server after issuing a command that expects data to be written.
See the Net::POP3 and Net::SMTP modules for examples of this.
Normally the values returned by message()
and code()
are
obtained from the remote server, but in a few circumstances, as
detailed below, Net::Cmd
will return values that it sets. You
can alter this behavior by overriding DEF_REPLY_CODE()
to specify
a different default reply code, or overriding one of the specific
error handling methods below.
code()
will return ``421'' (temporary connection failure) and
message()
will return undef.
IO::Handle
is closed, or if there are
any read or write failures, the file handle will be forced closed,
and code()
will return ``421'' (temporary connection failure)
and message()
will return ``[$pkg] Connection closed''
(where $pkg is the name of the class that subclassed Net::Cmd
).
The _set_status_closed()
method can be overridden to set a different
message (by calling set_status())
or otherwise trap this error.
code()
will return ``421''
(temporary connection failure) and message()
will return
``[$pkg] Timeout'' (where $pkg is the name of the class
that subclassed Net::Cmd
). The _set_status_timeout()
method
can be overridden to set a different message (by calling set_status())
or otherwise trap this error.
Net::Cmd
exports six subroutines, five of these, CMD_INFO
, CMD_OK
,
CMD_MORE
, CMD_REJECT
and CMD_ERROR
, correspond to possible results
of response
and status
. The sixth is CMD_PENDING
.
Graham Barr <gbarr@pobox.com>.
Steve Hay <shay@cpan.org> is now maintaining libnet as of version 1.22_02.
Copyright (C) 1995-2006 Graham Barr. All rights reserved.
Copyright (C) 2013-2016 Steve Hay. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e. under the terms of either the GNU General Public License or the Artistic License, as specified in the LICENCE file.
Net::Cmd - Network Command class |