SWISH::Prog::Doc - Document object for passing to Swish-e indexer
# subclass SWISH::Prog::Doc # and create _filter() methods package My::Prog::Doc use base qw( SWISH::Prog::Doc ); sub url_filter { my $doc = shift; my $url = $doc->url; $url =~ s/my.foo.com/my.bar.org/; $doc->url( $url ); } sub content_filter { my $doc = shift; my $buf = $doc->content; $buf =~ s/foo/bar/gi; $doc->content( $buf ); } 1;
SWISH::Prog::Doc is the base class for Doc objects in the SWISH::Prog framework. Doc objects are created and returned by the SWISH::Prog->fetch() method.
You can subclass SWISH::Prog::Doc and add _filter() methods to alter the values of the Doc object before it is returned from fetch().
If you subclass SWISH::Prog, you MUST subclass SWISH::Prog::Doc as well, even if only as a placeholder.
Example:
package MyApp::Prog; use base qw( SWISH::Prog ); sub ok { my $self = shift; my $doc = shift; 1; # everything is permitted (but not all things are profitable...) } 1; package MyApp::Prog::Doc; # must use same base class name as above 1;
Default is 0. Set to 1 (true) for verbage on stderr.
All of the following methods may be overridden when subclassing this module.
Instantiate Doc object.
All of the following params are also available as accessors/mutators.
** Swish-e verison 2.x only **
Calls any defined *_filter() methods. Called by new() after init().
Public initialization method. Override this method in order to initialize a Doc object. Called in new() after private initialization and before filters().
Return the Doc object rendered as a scalar string, ready to be indexed. This will include the proper headers. See SWISH::Prog::Headers.
NOTE: as_string() is also used if you use a Doc object as a string. Example:
print $doc->as_string; # one way print $doc; # same thing
Every object attribute may have a *_filter() method defined for it as well. As part of the object initialization in new(), each attribute is tested with can() to see if a corresponding _filter() method exists, and if so, the object is passed. See the SYNOPIS for examples.
Filter method return values are ignored. Save whatever changes you want directly in the passed object.
http://swish-e.org/docs/
SWISH::Prog::MIME, SWISH::Prog::Headers, SWISH::Prog::Parser
Peter Karman, <perl@peknet.com>
Thanks to www.atomiclearning.com for sponsoring the development of this module.
Copyright 2006 by Peter Karman
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install SWISH::Prog, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SWISH::Prog
CPAN shell
perl -MCPAN -e shell install SWISH::Prog
For more information on module installation, please visit the detailed CPAN module installation guide.