The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PurpleWiki::View::Filter - A Quick Access View Filter.

SYNOPSIS

    #!/usr/bin/perl
    #
    # This program prints out all the image links on a page.
    # 
    use strict;
    use warnings;
    use PurpleWiki::Config;
    use PurpleWiki::Database::Page;
    use PurpleWiki::Parser::WikiText;
    use PurpleWiki::View::Filter;
    use Data::Dumper;

    my $pageName = shift || die "Usage: $0 page\n";

    my $config = new PurpleWiki::Config('/path/to/wikidb');
    my $parser = new PurpleWiki::Parser::WikiText;
    my $filter = new PurpleWiki::View::Filter();

    my $page = new PurpleWiki::Database::Page(id => $pageName);
                                              

    die "$page does not exist!\n" if not $page->pageExists();
    $page->openPage();

    my $tree = $parser->parse($page->getText()->getText(), 'add_node_ids'=>0);

    $filter->setFilter(imageMain => sub {print shift->content."\n"});
    $filter->process($tree);

DESCRIPTION

Filter allows the creation of quick, on the fly, view drivers without the hassle of defining a new class and doing OO stuff. You simply pass in the name of the method you're "overloading" followed by the subroutine to call for it.

METHODS

new(useOO => $boolean, start => $subRef, stop => $subRef, methodName => $subRef, ...)

Returns a new PurpleWiki::View::Filter object.

useOO is a boolean variable, if it's true then the subroutines are called with $self as their first argument, otherwise they're called like normal functions. The default is 0.

start and stop are special subroutines to be called before processing beings and after, respectively. The default is a noop().

The remainder of the arguments are methodName/suboutine reference pairs. If methodName is called then the corresponding subroutine is called instead of the real method.

process($tree)

Causes the PurpleWiki::Tree $tree to be traversed. This is the main access point to the object. Call the view() method, like on a normal view driver, would cause the special start and stop methods not to be called.

setFilter(methodName => $subRef)

Adds a filter for methodName with subroutine reference $subRef

setFilters(methodName => $subRef, ...)

Like setFilter() but allows multiple definitions.

AUTHORS

Matthew O'Connor, <matthew@canonical.org>

SEE ALSO

PurpleWiki::View::Driver