Net::NNTP::Functions - code to implement NNTP-standard functions


newslib documentation Contained in the newslib distribution.

Index


Code Index:

NAME

Top

Net::NNTP::Functions - code to implement NNTP-standard functions

SYNOPSIS

Top

  use Net::NNTP::Functions;

  my ($first1, $last1) = messagespec( "4-12" );	 # Returns (4, 12)
  my ($first2, $last2) = messagespec( 4 );	 # Returns (4, undef)
  my ($first3, $last3) = messagespec( [4, 12] ); # Returns (4, 12)
  my ($first4, $last4) = messagespec( "4-3" );   # Returns (4, -1)

  my $match = wildmat( 'rec.*', $string );

DESCRIPTION

Top

The NNTP specification, as described by Net::NNTP, defines two speficiations: MESSAGE-SPEC, for defining a range of messages, and PATTERN, for pattern-matching over NNTP. These functions attempt to implement this behaviour.

Functions

messagespec ( ARRAYREF | MESSAGEID | MESSAGENUMBER )

Returns an array (or array reference) of two items (FIRST and LAST for reference), based on the passed item. If we get an ARRAYREF, it's assumed to be list of two items FIRST and LAST; if it's a MESSAGEID or MESSAGENUMBER then FIRST is the value, and LAST is 'undef';

If the LAST item is less than FIRST, then we set LAST to '-1'. This allows later functions to (correctly) interpret this for a list of all items after FIRST.

wildmat ( EXPRESSION, STRING )

Implements the WILDMAT format, as described in the Net::NNTP page (which I won't repeat here).

Doesn't currently implement the entire functionality; all that currently works is the anchoring, '*', and '?'. Ranges of characters ('[]') and invertings ('^') don't work. (Correction: they might work, I haven't tried).

Taken from http://cvs.trainedmonkey.com/viewcvs.cgi/colobus/colobus?rev=1.41 .

SEE ALSO

Top

Net::NNTP, specifically its manual page sections on WILDMAT and MESSAGESPEC.

TODO

Top

Write the rest of the functionality for wildmat().

AUTHOR

Top

Tim Skirvin <tskirvin@killfile.org>. wildmat() in its current form was written by Jim Winstead Jr.

COPYRIGHT

Top


newslib documentation Contained in the newslib distribution.
$VERSION = "0.21";
package Net::NNTP::Functions;
our $VERSION = "0.21";     
# -*- Perl -*- 		# Fri Oct 10 10:17:44 CDT 2003 
#############################################################################
# Written by Tim Skirvin <tskirvin@killfile.org>.  Copyright 2003, Tim
# Skirvin.  Redistribution terms are below.
#############################################################################

###############################################################################
### main() ####################################################################
###############################################################################

use strict;
use Exporter;

use vars qw( @EXPORT @EXPORT_OK @ISA );
@ISA    = "Exporter";
@EXPORT = qw( messagespec wildmat );

###############################################################################
### Methods ###################################################################
###############################################################################

sub messagespec {
  my ($spec) = @_;
  my ($first, $last);

  if (ref $spec) {      		  	# List of two numbers
    ($first, $last) = @{$spec};
    $last = -1 if ($last < $first);
  } elsif ($spec =~ m/^\s*(\d+)\s*-?\s*(\d+)\s*$/) { # Two numbers
    $first = $1;  $last = $2;
    $last = -1 if ($last < $first);
  } else {      				# Message-ID or a single number
    $first = $spec;  $last = undef;
  }
  wantarray ? ($first, $last) : [ $first, $last ];
}

sub wildmat ($$) {
  my ($expr, $string) = @_;
  $expr =~ s/(?<!\\)\./\\./g;	# Escape '.'
  $expr =~ s/(?<!\\)\$/\\\$/g;	# Escape '$'
  $expr =~ s/(?<!\\)\?/./g;	# '?' functionality
  $expr =~ s/(?<!\\)\*/.*/g;	# '*' functionality
  return $string =~ /^$expr$/;
}

1;

###############################################################################
### Version History ###########################################################
###############################################################################
# v0.2a 	Fri Oct 10 10:17:44 CDT 2003 
### First commented version.
# v0.21		Thu Apr 22 11:42:13 CDT 2004 
### No real changes; just version number change.