.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.13)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.el \{\
.    de IX
..
.\}
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Filter::Simple 3pm"
.TH Filter::Simple 3pm "2009-04-11" "perl v5.10.1" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Filter::Simple \- Simplified source filtering
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& # in MyFilter.pm:
\&
\&     package MyFilter;
\&
\&     use Filter::Simple;
\&     
\&     FILTER { ... };
\&
\&     # or just:
\&     #
\&     # use Filter::Simple sub { ... };
\&
\& # in user\*(Aqs code:
\&
\&     use MyFilter;
\&
\&     # this code is filtered
\&
\&     no MyFilter;
\&
\&     # this code is not
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
.SS "The Problem"
.IX Subsection "The Problem"
Source filtering is an immensely powerful feature of recent versions of Perl.
It allows one to extend the language itself (e.g. the Switch module), to 
simplify the language (e.g. Language::Pythonesque), or to completely recast the
language (e.g. Lingua::Romana::Perligata). Effectively, it allows one to use
the full power of Perl as its own, recursively applied, macro language.
.PP
The excellent Filter::Util::Call module (by Paul Marquess) provides a
usable Perl interface to source filtering, but it is often too powerful
and not nearly as simple as it could be.
.PP
To use the module it is necessary to do the following:
.IP "1." 4
Download, build, and install the Filter::Util::Call module.
(If you have Perl 5.7.1 or later, this is already done for you.)
.IP "2." 4
Set up a module that does a \f(CW\*(C`use Filter::Util::Call\*(C'\fR.
.IP "3." 4
Within that module, create an \f(CW\*(C`import\*(C'\fR subroutine.
.IP "4." 4
Within the \f(CW\*(C`import\*(C'\fR subroutine do a call to \f(CW\*(C`filter_add\*(C'\fR, passing
it either a subroutine reference.
.IP "5." 4
Within the subroutine reference, call \f(CW\*(C`filter_read\*(C'\fR or \f(CW\*(C`filter_read_exact\*(C'\fR
to \*(L"prime\*(R" \f(CW$_\fR with source code data from the source file that will
\&\f(CW\*(C`use\*(C'\fR your module. Check the status value returned to see if any
source code was actually read in.
.IP "6." 4
Process the contents of \f(CW$_\fR to change the source code in the desired manner.
.IP "7." 4
Return the status value.
.IP "8." 4
If the act of unimporting your module (via a \f(CW\*(C`no\*(C'\fR) should cause source
code filtering to cease, create an \f(CW\*(C`unimport\*(C'\fR subroutine, and have it call
\&\f(CW\*(C`filter_del\*(C'\fR. Make sure that the call to \f(CW\*(C`filter_read\*(C'\fR or
\&\f(CW\*(C`filter_read_exact\*(C'\fR in step 5 will not accidentally read past the
\&\f(CW\*(C`no\*(C'\fR. Effectively this limits source code filters to line-by-line
operation, unless the \f(CW\*(C`import\*(C'\fR subroutine does some fancy
pre-pre-parsing of the source code it's filtering.
.PP
For example, here is a minimal source code filter in a module named
\&\s-1BANG\s0.pm. It simply converts every occurrence of the sequence \f(CW\*(C`BANG\es+BANG\*(C'\fR
to the sequence \f(CW\*(C`die \*(AqBANG\*(Aq if $BANG\*(C'\fR in any piece of code following a
\&\f(CW\*(C`use BANG;\*(C'\fR statement (until the next \f(CW\*(C`no BANG;\*(C'\fR statement, if any):
.PP
.Vb 1
\&    package BANG;
\& 
\&    use Filter::Util::Call ;
\&
\&    sub import {
\&        filter_add( sub {
\&        my $caller = caller;
\&        my ($status, $no_seen, $data);
\&        while ($status = filter_read()) {
\&            if (/^\es*no\es+$caller\es*;\es*?$/) {
\&                $no_seen=1;
\&                last;
\&            }
\&            $data .= $_;
\&            $_ = "";
\&        }
\&        $_ = $data;
\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g
\&            unless $status < 0;
\&        $_ .= "no $class;\en" if $no_seen;
\&        return 1;
\&        })
\&    }
\&
\&    sub unimport {
\&        filter_del();
\&    }
\&
\&    1 ;
.Ve
.PP
This level of sophistication puts filtering out of the reach of
many programmers.
.SS "A Solution"
.IX Subsection "A Solution"
The Filter::Simple module provides a simplified interface to
Filter::Util::Call; one that is sufficient for most common cases.
.PP
Instead of the above process, with Filter::Simple the task of setting up
a source code filter is reduced to:
.IP "1." 4
Download and install the Filter::Simple module.
(If you have Perl 5.7.1 or later, this is already done for you.)
.IP "2." 4
Set up a module that does a \f(CW\*(C`use Filter::Simple\*(C'\fR and then
calls \f(CW\*(C`FILTER { ... }\*(C'\fR.
.IP "3." 4
Within the anonymous subroutine or block that is passed to
\&\f(CW\*(C`FILTER\*(C'\fR, process the contents of \f(CW$_\fR to change the source code in
the desired manner.
.PP
In other words, the previous example, would become:
.PP
.Vb 2
\&    package BANG;
\&    use Filter::Simple;
\&    
\&    FILTER {
\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;
\&    };
\&
\&    1 ;
.Ve
.PP
Note that the source code is passed as a single string, so any regex that
uses \f(CW\*(C`^\*(C'\fR or \f(CW\*(C`$\*(C'\fR to detect line boundaries will need the \f(CW\*(C`/m\*(C'\fR flag.
.SS "Disabling or changing <no> behaviour"
.IX Subsection "Disabling or changing <no> behaviour"
By default, the installed filter only filters up to a line consisting of one of
the three standard source \*(L"terminators\*(R":
.PP
.Vb 1
\&    no ModuleName;  # optional comment
.Ve
.PP
or:
.PP
.Vb 1
\&    _\|_END_\|_
.Ve
.PP
or:
.PP
.Vb 1
\&    _\|_DATA_\|_
.Ve
.PP
but this can be altered by passing a second argument to \f(CW\*(C`use Filter::Simple\*(C'\fR
or \f(CW\*(C`FILTER\*(C'\fR (just remember: there's \fIno\fR comma after the initial block when
you use \f(CW\*(C`FILTER\*(C'\fR).
.PP
That second argument may be either a \f(CW\*(C`qr\*(C'\fR'd regular expression (which is then
used to match the terminator line), or a defined false value (which indicates
that no terminator line should be looked for), or a reference to a hash
(in which case the terminator is the value associated with the key
\&\f(CW\*(Aqterminator\*(Aq\fR.
.PP
For example, to cause the previous filter to filter only up to a line of the
form:
.PP
.Vb 1
\&    GNAB esu;
.Ve
.PP
you would write:
.PP
.Vb 2
\&    package BANG;
\&    use Filter::Simple;
\&    
\&    FILTER {
\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;
\&    }
\&    qr/^\es*GNAB\es+esu\es*;\es*?$/;
.Ve
.PP
or:
.PP
.Vb 4
\&    FILTER {
\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;
\&    }
\&    { terminator => qr/^\es*GNAB\es+esu\es*;\es*?$/ };
.Ve
.PP
and to prevent the filter's being turned off in any way:
.PP
.Vb 2
\&    package BANG;
\&    use Filter::Simple;
\&    
\&    FILTER {
\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;
\&    }
\&    "";    # or: 0
.Ve
.PP
or:
.PP
.Vb 4
\&    FILTER {
\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;
\&    }
\&    { terminator => "" };
.Ve
.PP
\&\fBNote that, no matter what you set the terminator pattern to,
the actual terminator itself \f(BImust\fB be contained on a single source line.\fR
.SS "All-in-one interface"
.IX Subsection "All-in-one interface"
Separating the loading of Filter::Simple:
.PP
.Vb 1
\&    use Filter::Simple;
.Ve
.PP
from the setting up of the filtering:
.PP
.Vb 1
\&    FILTER { ... };
.Ve
.PP
is useful because it allows other code (typically parser support code
or caching variables) to be defined before the filter is invoked.
However, there is often no need for such a separation.
.PP
In those cases, it is easier to just append the filtering subroutine and
any terminator specification directly to the \f(CW\*(C`use\*(C'\fR statement that loads
Filter::Simple, like so:
.PP
.Vb 3
\&    use Filter::Simple sub {
\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;
\&    };
.Ve
.PP
This is exactly the same as:
.PP
.Vb 6
\&    use Filter::Simple;
\&    BEGIN {
\&        Filter::Simple::FILTER {
\&            s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;
\&        };
\&    }
.Ve
.PP
except that the \f(CW\*(C`FILTER\*(C'\fR subroutine is not exported by Filter::Simple.
.SS "Filtering only specific components of source code"
.IX Subsection "Filtering only specific components of source code"
One of the problems with a filter like:
.PP
.Vb 1
\&    use Filter::Simple;
\&
\&    FILTER { s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g };
.Ve
.PP
is that it indiscriminately applies the specified transformation to
the entire text of your source program. So something like:
.PP
.Vb 2
\&    warn \*(AqBANG BANG, YOU\*(AqRE DEAD\*(Aq;
\&    BANG BANG;
.Ve
.PP
will become:
.PP
.Vb 2
\&    warn \*(Aqdie \*(AqBANG\*(Aq if $BANG, YOU\*(AqRE DEAD\*(Aq;
\&    die \*(AqBANG\*(Aq if $BANG;
.Ve
.PP
It is very common when filtering source to only want to apply the filter
to the non-character-string parts of the code, or alternatively to \fIonly\fR
the character strings.
.PP
Filter::Simple supports this type of filtering by automatically
exporting the \f(CW\*(C`FILTER_ONLY\*(C'\fR subroutine.
.PP
\&\f(CW\*(C`FILTER_ONLY\*(C'\fR takes a sequence of specifiers that install separate
(and possibly multiple) filters that act on only parts of the source code.
For example:
.PP
.Vb 1
\&    use Filter::Simple;
\&
\&    FILTER_ONLY
\&        code      => sub { s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g },
\&        quotelike => sub { s/BANG\es+BANG/CHITTY CHITTY/g };
.Ve
.PP
The \f(CW"code"\fR subroutine will only be used to filter parts of the source
code that are not quotelikes, \s-1POD\s0, or \f(CW\*(C`_\|_DATA_\|_\*(C'\fR. The \f(CW\*(C`quotelike\*(C'\fR
subroutine only filters Perl quotelikes (including here documents).
.PP
The full list of alternatives is:
.ie n .IP """code""" 4
.el .IP "\f(CW``code''\fR" 4
.IX Item """code"""
Filters only those sections of the source code that are not quotelikes, \s-1POD\s0, or
\&\f(CW\*(C`_\|_DATA_\|_\*(C'\fR.
.ie n .IP """code_no_comments""" 4
.el .IP "\f(CW``code_no_comments''\fR" 4
.IX Item """code_no_comments"""
Filters only those sections of the source code that are not quotelikes, \s-1POD\s0,
comments, or \f(CW\*(C`_\|_DATA_\|_\*(C'\fR.
.ie n .IP """executable""" 4
.el .IP "\f(CW``executable''\fR" 4
.IX Item """executable"""
Filters only those sections of the source code that are not \s-1POD\s0 or \f(CW\*(C`_\|_DATA_\|_\*(C'\fR.
.ie n .IP """executable_no_comments""" 4
.el .IP "\f(CW``executable_no_comments''\fR" 4
.IX Item """executable_no_comments"""
Filters only those sections of the source code that are not \s-1POD\s0, comments, or \f(CW\*(C`_\|_DATA_\|_\*(C'\fR.
.ie n .IP """quotelike""" 4
.el .IP "\f(CW``quotelike''\fR" 4
.IX Item """quotelike"""
Filters only Perl quotelikes (as interpreted by
\&\f(CW&Text::Balanced::extract_quotelike\fR).
.ie n .IP """string""" 4
.el .IP "\f(CW``string''\fR" 4
.IX Item """string"""
Filters only the string literal parts of a Perl quotelike (i.e. the 
contents of a string literal, either half of a \f(CW\*(C`tr///\*(C'\fR, the second
half of an \f(CW\*(C`s///\*(C'\fR).
.ie n .IP """regex""" 4
.el .IP "\f(CW``regex''\fR" 4
.IX Item """regex"""
Filters only the pattern literal parts of a Perl quotelike (i.e. the 
contents of a \f(CW\*(C`qr//\*(C'\fR or an \f(CW\*(C`m//\*(C'\fR, the first half of an \f(CW\*(C`s///\*(C'\fR).
.ie n .IP """all""" 4
.el .IP "\f(CW``all''\fR" 4
.IX Item """all"""
Filters everything. Identical in effect to \f(CW\*(C`FILTER\*(C'\fR.
.PP
Except for \f(CW\*(C`FILTER_ONLY code => sub {...}\*(C'\fR, each of
the component filters is called repeatedly, once for each component
found in the source code.
.PP
Note that you can also apply two or more of the same type of filter in
a single \f(CW\*(C`FILTER_ONLY\*(C'\fR. For example, here's a simple 
macro-preprocessor that is only applied within regexes,
with a final debugging pass that prints the resulting source code:
.PP
.Vb 6
\&    use Regexp::Common;
\&    FILTER_ONLY
\&        regex => sub { s/!\e[/[^/g },
\&        regex => sub { s/%d/$RE{num}{int}/g },
\&        regex => sub { s/%f/$RE{num}{real}/g },
\&        all   => sub { print if $::DEBUG };
.Ve
.SS "Filtering only the code parts of source code"
.IX Subsection "Filtering only the code parts of source code"
Most source code ceases to be grammatically correct when it is broken up
into the pieces between string literals and regexes. So the \f(CW\*(Aqcode\*(Aq\fR
and \f(CW\*(Aqcode_no_comments\*(Aq\fR component filter behave slightly differently
from the other partial filters described in the previous section.
.PP
Rather than calling the specified processor on each individual piece of
code (i.e. on the bits between quotelikes), the \f(CW\*(Aqcode...\*(Aq\fR partial
filters operate on the entire source code, but with the quotelike bits
(and, in the case of \f(CW\*(Aqcode_no_comments\*(Aq\fR, the comments) \*(L"blanked out\*(R".
.PP
That is, a \f(CW\*(Aqcode...\*(Aq\fR filter \fIreplaces\fR each quoted string, quotelike,
regex, \s-1POD\s0, and _\|_DATA_\|_ section with a placeholder. The
delimiters of this placeholder are the contents of the \f(CW$;\fR variable
at the time the filter is applied (normally \f(CW"\e034"\fR). The remaining
four bytes are a unique identifier for the component being replaced.
.PP
This approach makes it comparatively easy to write code preprocessors
without worrying about the form or contents of strings, regexes, etc.
.PP
For convenience, during a \f(CW\*(Aqcode...\*(Aq\fR filtering operation, Filter::Simple
provides a package variable (\f(CW$Filter::Simple::placeholder\fR) that
contains a pre-compiled regex that matches any placeholder...and
captures the identifier within the placeholder. Placeholders can be
moved and re-ordered within the source code as needed.
.PP
In addition, a second package variable (\f(CW@Filter::Simple::components\fR)
contains a list of the various pieces of \f(CW$_\fR, as they were originally split
up to allow placeholders to be inserted.
.PP
Once the filtering has been applied, the original strings, regexes, \s-1POD\s0,
etc. are re-inserted into the code, by replacing each placeholder with
the corresponding original component (from \f(CW@components\fR). Note that
this means that the \f(CW@components\fR variable must be treated with extreme
care within the filter. The \f(CW@components\fR array stores the \*(L"back\-
translations\*(R" of each placeholder inserted into \f(CW$_\fR, as well as the
interstitial source code between placeholders. If the placeholder
backtranslations are altered in \f(CW@components\fR, they will be similarly
changed when the placeholders are removed from \f(CW$_\fR after the filter
is complete.
.PP
For example, the following filter detects concatenated pairs of
strings/quotelikes and reverses the order in which they are
concatenated:
.PP
.Vb 2
\&    package DemoRevCat;
\&    use Filter::Simple;
\&
\&    FILTER_ONLY code => sub {
\&        my $ph = $Filter::Simple::placeholder;
\&        s{ ($ph) \es* [.] \es* ($ph) }{ $2.$1 }gx
\&    };
.Ve
.PP
Thus, the following code:
.PP
.Vb 1
\&    use DemoRevCat;
\&
\&    my $str = "abc" . q(def);
\&
\&    print "$str\en";
.Ve
.PP
would become:
.PP
.Vb 1
\&    my $str = q(def)."abc";
\&
\&    print "$str\en";
.Ve
.PP
and hence print:
.PP
.Vb 1
\&    defabc
.Ve
.ie n .SS "Using Filter::Simple with an explicit ""import"" subroutine"
.el .SS "Using Filter::Simple with an explicit \f(CWimport\fP subroutine"
.IX Subsection "Using Filter::Simple with an explicit import subroutine"
Filter::Simple generates a special \f(CW\*(C`import\*(C'\fR subroutine for
your module (see \*(L"How it works\*(R") which would normally replace any
\&\f(CW\*(C`import\*(C'\fR subroutine you might have explicitly declared.
.PP
However, Filter::Simple is smart enough to notice your existing
\&\f(CW\*(C`import\*(C'\fR and Do The Right Thing with it.
That is, if you explicitly define an \f(CW\*(C`import\*(C'\fR subroutine in a package
that's using Filter::Simple, that \f(CW\*(C`import\*(C'\fR subroutine will still
be invoked immediately after any filter you install.
.PP
The only thing you have to remember is that the \f(CW\*(C`import\*(C'\fR subroutine
\&\fImust\fR be declared \fIbefore\fR the filter is installed. If you use \f(CW\*(C`FILTER\*(C'\fR
to install the filter:
.PP
.Vb 1
\&    package Filter::TurnItUpTo11;
\&
\&    use Filter::Simple;
\&
\&    FILTER { s/(\ew+)/\eU$1/ };
.Ve
.PP
that will almost never be a problem, but if you install a filtering
subroutine by passing it directly to the \f(CW\*(C`use Filter::Simple\*(C'\fR
statement:
.PP
.Vb 1
\&    package Filter::TurnItUpTo11;
\&
\&    use Filter::Simple sub{ s/(\ew+)/\eU$1/ };
.Ve
.PP
then you must make sure that your \f(CW\*(C`import\*(C'\fR subroutine appears before
that \f(CW\*(C`use\*(C'\fR statement.
.SS "Using Filter::Simple and Exporter together"
.IX Subsection "Using Filter::Simple and Exporter together"
Likewise, Filter::Simple is also smart enough
to Do The Right Thing if you use Exporter:
.PP
.Vb 3
\&    package Switch;
\&    use base Exporter;
\&    use Filter::Simple;
\&
\&    @EXPORT    = qw(switch case);
\&    @EXPORT_OK = qw(given  when);
\&
\&    FILTER { $_ = magic_Perl_filter($_) }
.Ve
.PP
Immediately after the filter has been applied to the source,
Filter::Simple will pass control to Exporter, so it can do its magic too.
.PP
Of course, here too, Filter::Simple has to know you're using Exporter
before it applies the filter. That's almost never a problem, but if you're
nervous about it, you can guarantee that things will work correctly by
ensuring that your \f(CW\*(C`use base Exporter\*(C'\fR always precedes your
\&\f(CW\*(C`use Filter::Simple\*(C'\fR.
.SS "How it works"
.IX Subsection "How it works"
The Filter::Simple module exports into the package that calls \f(CW\*(C`FILTER\*(C'\fR
(or \f(CW\*(C`use\*(C'\fRs it directly) \*(-- such as package \*(L"\s-1BANG\s0\*(R" in the above example \*(--
two automagically constructed
subroutines \*(-- \f(CW\*(C`import\*(C'\fR and \f(CW\*(C`unimport\*(C'\fR \*(-- which take care of all the
nasty details.
.PP
In addition, the generated \f(CW\*(C`import\*(C'\fR subroutine passes its own argument
list to the filtering subroutine, so the \s-1BANG\s0.pm filter could easily 
be made parametric:
.PP
.Vb 1
\&    package BANG;
\& 
\&    use Filter::Simple;
\&    
\&    FILTER {
\&        my ($die_msg, $var_name) = @_;
\&        s/BANG\es+BANG/die \*(Aq$die_msg\*(Aq if \e${$var_name}/g;
\&    };
\&
\&    # and in some user code:
\&
\&    use BANG "BOOM", "BAM";  # "BANG BANG" becomes: die \*(AqBOOM\*(Aq if $BAM
.Ve
.PP
The specified filtering subroutine is called every time a \f(CW\*(C`use BANG\*(C'\fR is
encountered, and passed all the source code following that call, up to
either the next \f(CW\*(C`no BANG;\*(C'\fR (or whatever terminator you've set) or the
end of the source file, whichever occurs first. By default, any \f(CW\*(C`no
BANG;\*(C'\fR call must appear by itself on a separate line, or it is ignored.
.SH "AUTHOR"
.IX Header "AUTHOR"
Damian Conway
.SH "CONTACT"
.IX Header "CONTACT"
Filter::Simple is now maintained by the Perl5\-Porters.
Please submit bug via the \f(CW\*(C`perlbug\*(C'\fR tool that comes with your perl.
For usage instructions, read \f(CW\*(C`perldoc perlbug\*(C'\fR or possibly \f(CW\*(C`man perlbug\*(C'\fR.
For mostly anything else, please contact <perl5\-porters@perl.org>.
.PP
Maintainer of the \s-1CPAN\s0 release is Steffen Mueller <smueller@cpan.org>.
Contact him with technical difficulties with respect to the packaging of the
\&\s-1CPAN\s0 module.
.PP
Praise of the module, flowers, and presents still go to the author,
Damian Conway <damian@conway.org>.
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
.Vb 3
\&    Copyright (c) 2000\-2008, Damian Conway. All Rights Reserved.
\&    This module is free software. It may be used, redistributed
\&    and/or modified under the same terms as Perl itself.
.Ve
