Upgrade to CGI-3.14.
[p5sagit/p5-mst-13.2.git] / lib / Net / NNTP.pm
index 2644397..0467a80 100644 (file)
@@ -14,15 +14,21 @@ use Carp;
 use Time::Local;
 use Net::Config;
 
-$VERSION = "2.19"; # $Id: //depot/libnet/Net/NNTP.pm#8$
+$VERSION = "2.23";
 @ISA     = qw(Net::Cmd IO::Socket::INET);
 
 sub new
 {
  my $self = shift;
  my $type = ref($self) || $self;
- my $host = shift if @_ % 2;
- my %arg  = @_;
+ my ($host,%arg);
+ if (@_ % 2) {
+   $host = shift ;
+   %arg  = @_;
+ } else {
+   %arg = @_;
+   $host=delete $arg{Host};
+ }
  my $obj;
 
  $host ||= $ENV{NNTPSERVER} || $ENV{NEWSHOST};
@@ -60,7 +66,7 @@ sub new
 
  my $c = $obj->code;
  my @m = $obj->message;
+
  unless(exists $arg{Reader} && $arg{Reader} == 0) {
    # if server is INN and we have transfer rights the we are currently
    # talking to innd not nnrpd
@@ -81,13 +87,18 @@ sub new
  $obj;
 }
 
+sub host {
+ my $me = shift;
+ ${*$me}{'net_nntp_host'};
+}
+
 sub debug_text
 {
  my $nntp = shift;
  my $inout = shift;
  my $text = shift;
 
- if(($nntp->code == 350 && $text =~ /^(\S+)/)
+ if((ref($nntp) and $nntp->code == 350 and $text =~ /^(\S+)/)
     || ($text =~ /^(authinfo\s+pass)/io)) 
   {
    $text = "$1 ....\n"
@@ -116,6 +127,14 @@ sub article
     : undef;
 }
 
+sub articlefh {
+ @_ >= 1 && @_ <= 2 or croak 'usage: $nntp->articlefh( [ MSGID ] )';
+ my $nntp = shift;
+
+ return unless $nntp->_ARTICLE(@_);
+ return $nntp->tied_fh;
+}
+
 sub authinfo
 {
  @_ == 3 or croak 'usage: $nntp->authinfo( USER, PASS )';
@@ -147,6 +166,14 @@ sub body
     : undef;
 }
 
+sub bodyfh
+{
+ @_ >= 1 && @_ <= 2 or croak 'usage: $nntp->bodyfh( [ MSGID ] )';
+ my $nntp = shift;
+ return unless $nntp->_BODY(@_);
+ return $nntp->tied_fh;
+}
+
 sub head
 {
  @_ >= 1 && @_ <= 3 or croak 'usage: $nntp->head( [ MSGID ], [ FH ] )';
@@ -160,6 +187,14 @@ sub head
     : undef;
 }
 
+sub headfh
+{
+ @_ >= 1 && @_ <= 2 or croak 'usage: $nntp->headfh( [ MSGID ] )';
+ my $nntp = shift;
+ return unless $nntp->_HEAD(@_);
+ return $nntp->tied_fh;
+}
+
 sub nntpstat
 {
  @_ == 1 || @_ == 2 or croak 'usage: $nntp->nntpstat( [ MSGID ] )';
@@ -296,6 +331,12 @@ sub post
     : undef;
 }
 
+sub postfh {
+  my $nntp = shift;
+  return unless $nntp->_POST();
+  return $nntp->tied_fh;
+}
+
 sub quit
 {
  @_ == 1 or croak 'usage: $nntp->quit()';
@@ -514,9 +555,14 @@ sub _msg_arg
   {
    if(ref($spec))
     {
-     $arg = $spec->[0] . "-";
-     $arg .= $spec->[1]
-       if defined $spec->[1] && $spec->[1] > $spec->[0];
+     $arg = $spec->[0];
+     if(defined $spec->[1])
+      {
+       $arg .= "-"
+         if $spec->[1] != $spec->[0];
+       $arg .= $spec->[1]
+         if $spec->[1] > $spec->[0];
+      }
     }
    else
     {
@@ -660,7 +706,7 @@ Net::NNTP - NNTP Client class
 =head1 SYNOPSIS
 
     use Net::NNTP;
-    
+
     $nntp = Net::NNTP->new("some.host.name");
     $nntp->quit;
 
@@ -677,13 +723,19 @@ in RFC977. C<Net::NNTP> inherits its communication methods from C<Net::Cmd>
 
 This is the constructor for a new Net::NNTP object. C<HOST> is the
 name of the remote host to which a NNTP connection is required. If not
-given two environment variables are checked, first C<NNTPSERVER> then
+given then it may be passed as the C<Host> option described below. If no host is passed
+then two environment variables are checked, first C<NNTPSERVER> then
 C<NEWSHOST>, then C<Net::Config> is checked, and if a host is not found
 then C<news> is used.
 
 C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
 Possible options are:
 
+B<Host> - NNTP host to connect to. It may be a single scalar, as defined for
+the C<PeerAddr> option in L<IO::Socket::INET>, or a reference to
+an array with hosts to try in turn. The L</host> method will return the value
+which was used to connect to the host.
+
 B<Timeout> - Maximum time, in seconds, to wait for a response from the
 NNTP server, a value of zero will cause all IO operations to block.
 (default: 120)
@@ -713,9 +765,9 @@ Retrieve the header, a blank line, then the body (text) of the
 specified article. 
 
 If C<FH> is specified then it is expected to be a valid filehandle
-and the result will be printed to it, on sucess a true value will be
-returned. If C<FH> is not specified then the return value, on sucess,
-will be a reference to an array containg the article requested, each
+and the result will be printed to it, on success a true value will be
+returned. If C<FH> is not specified then the return value, on success,
+will be a reference to an array containing the article requested, each
 entry in the array will contain one line of the article.
 
 If no arguments are passed then the current article in the currently
@@ -738,6 +790,16 @@ Like C<article> but only fetches the body of the article.
 
 Like C<article> but only fetches the headers for the article.
 
+=item articlefh ( [ MSGID|MSGNUM ] )
+
+=item bodyfh ( [ MSGID|MSGNUM ] )
+
+=item headfh ( [ MSGID|MSGNUM ] )
+
+These are similar to article(), body() and head(), but rather than
+returning the requested data directly, they return a tied filehandle
+from which to read the article.
+
 =item nntpstat ( [ MSGID|MSGNUM ] )
 
 The C<nntpstat> command is similar to the C<article> command except that no
@@ -795,12 +857,18 @@ that it will allow posting.
 
 =item authinfo ( USER, PASS )
 
+Authenticates to the server (using AUTHINFO USER / AUTHINFO PASS)
+using the supplied username and password.  Please note that the
+password is sent in clear text to the server.  This command should not
+be used with valuable passwords unless the connection to the server is
+somehow protected.
+
 =item list ()
 
 Obtain information about all the active newsgroups. The results is a reference
 to a hash where the key is a group name and each value is a reference to an
-array. The elements in this array are:- the first article number in the group,
-the last article number in the group and any information flags about the group.
+array. The elements in this array are:- the last article number in the group,
+the first article number in the group and any information flags about the group.
 
 =item newgroups ( SINCE [, DISTRIBUTIONS ])
 
@@ -837,6 +905,19 @@ C<datasend> and C<dataend> methods from L<Net::Cmd>
 
 C<MESSAGE> can be either an array of lines or a reference to an array.
 
+The message, either sent via C<datasend> or as the C<MESSAGE>
+parameter, must be in the format as described by RFC822 and must
+contain From:, Newsgroups: and Subject: headers.
+
+=item postfh ()
+
+Post a new article to the news server using a tied filehandle.  If
+posting is allowed, this method will return a tied filehandle that you
+can print() the contents of the article to be posted.  You must
+explicitly close() the filehandle when you are finished posting the
+article, and the return value from the close() call will indicate
+whether the message was successfully posted.
+
 =item slave ()
 
 Tell the remote server that I am not a user client, but probably another
@@ -1011,7 +1092,7 @@ the beginning of the test string just inside the open square
 bracket.
 
 The final operation uses the backslash character to
-invalidate the special meaning of the a open square bracket C<[>,
+invalidate the special meaning of an open square bracket C<[>,
 the asterisk, backslash or the question mark. Two backslashes in
 sequence will result in the evaluation of the backslash as a
 character with no special meaning.
@@ -1057,4 +1138,8 @@ Copyright (c) 1995-1997 Graham Barr. All rights reserved.
 This program is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself.
 
+=for html <hr>
+
+I<$Id: //depot/libnet/Net/NNTP.pm#18 $>
+
 =cut