Path: usenet.cise.ufl.edu!newsfeeds.nerdc.ufl.edu!news-dc-2.sprintlink.net!news-east1.sprintlink.net!news-peer1.sprintlink.net!news.sprintlink.net!news.maxwell.syr.edu!newsfeed.corridex.com!nntp2.savvis.net!inetarena.com!not-for-mail
From: [email protected] (Johan Vromans)
Newsgroups: comp.lang.perl.announce,comp.lang.perl.modules
Subject: ANNOUNCE: Text::Filter - base class to read and write text lines
Followup-To: comp.lang.perl.modules
Date: 9 Mar 1999 15:56:15 GMT
Organization: Compuware Uniface Amsterdam
Lines: 94
Approved: [email protected] (comp.lang.perl.announce)
Message-ID: <[email protected]>
NNTP-Posting-Host: halfdome.holdit.com
X-Disclaimer: The "Approved" header verifies header information for article transmission and does not imply approval of content.
Xref: usenet.cise.ufl.edu comp.lang.perl.announce:257 comp.lang.perl.modules:9268

INTRODUCTION

A plethora of tools exist that operate as filters: they get data from
a source, operate on this data, and write possibly modified data to a
destination. In the Unix world, these tools can be chained using a
technique called pipelining, where the output of one filter is
connected to the input of another filter. Some non-Unix worlds are
reported to have similar provisions.

To create Perl modules for filter functionality seems trivial at
first. Just open the input file, read and process it, and write output
to a destination file. But for really reusable modules this approach
is too simple. A reusable module should not read and write files
itself, but rely on the calling program to provide input as well as to
handle the output.

Text::Filter is a base class for modules that have in common that they
process text lines by reading from some source (usually a file),
manipulating the contents and writing something back to some
destination (usually some other file).

This module should be used by deriving modules from it. See the
documentation for an extensive example.

FEATURES

Every module that derives from Text::Filter inherits the following
instance methods:

* readline ()

  Returns the next line from the input stream, or undef if there is
  no more input.

* writeline ($line)

  Adds $line to the output stream.

* pushback ($line)

  Pushes a line of text back to the input stream.

When creating a new instance of this module, the input and output (or
only one of them) must be specified.

For input, this can be:

* A scalar, containing a file name. The named file will be opened,
  input lines will be read using <>.

* A file handle (glob). Lines will be read using <>.

* An instance of class IO::File. Lines will be read using <>.

* A reference to an array. Input lines will be shift()ed from the
  array.

* A reference to an anonymous subroutine. This routine will be called
  to get the next line of data.

For output:

* A scalar, containing a file name. The named file will be created
  automatically, output lines will be written using print().

* A file handle (glob). Lines will be written using print().

* An instance of class IO::File. Lines will be written using print().

* A reference to an array. Output lines will be push()ed into the
  array.

* A reference to an anonymous subroutine. This routine will be called
  to append a line of text to the destination.

Additional attributes can be used to specify actions to be performed
after the data is fetched, or prior to being written. For example, to
strip line endings upon input, and add them upon output.

AVAILABILITY

(web-page) http://www.squirrel.nl/people/jvromans/software.html
(download) http://www.perl.com/CPAN/authors/id/JV
           Archive: Text-Filter-1.5.tar.gz (or higher version)

----------------------------------------------------------------------------
Johan Vromans                                           [email protected]
Squirrel Consultancy                                Haarlem, the Netherlands
http://www.squirrel.nl                http://www.squirrel.nl/people/jvromans
PGP Key 2048/4783B14D     http://www.squirrel.nl/people/jvromans/pgpkey.html
----------------------- "Arms are made for hugging" ------------------------
------- End of forwarded message -------