NAME

SWISH::Prog::Doc - Document object for passing to Swish-e indexer

SYNOPSIS

  # 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;

DESCRIPTION

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;

METHODS

All of the following methods may be overridden when subclassing this module.

new

Instantiate Doc object.

All of the following params are also available as accessors/mutators.

url
type
content
parser
modtime
size
update

** Swish-e verison 2.x only **

debug
charset

filters

Calls any defined *_filter() methods. Called by new() after init().

init

Public initialization method. Override this method in order to initialize a Doc object. Called in new() after private initialization and before filters().

as_string

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

FILTERS

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.

SEE ALSO

http://swish-e.org/docs/

SWISH::Prog::Headers

AUTHOR

Peter Karman, <perl@peknet.com>

Thanks to www.atomiclearning.com for sponsoring the development of this module.

COPYRIGHT AND LICENSE

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.