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

NAME

SWISH::Prog::Object - index Perl objects with Swish-e

SYNOPSIS

    package My::Object;
    use base qw( SWISH::Prog::Object );
    
    1;
    
    package My::Object::Doc;
    use base qw( SWISH::Prog::Object::Doc );
    
    sub url_filter
    {
        my $doc = shift;
        my $obj = $doc->obj;
        $doc->url( $obj->method_I_want_as_url );
    }
    
    1;
    
    package main;
    use Carp;
    
    my $indexer = My::Object->new(
        methods => [qw( foo bar something something_else )],
        class   => 'My::Class',
        title   => 'mytitle',
        url     => 'myurl',
        modtime => 'mylastmod'
    );
    
    my $data = my_func_for_fetching_data();
    
    # $data is either iterator or arrayref of objects
    $indexer->create( $data );

DESCRIPTION

SWISH::Prog::Object is a SWISH::Prog subclass designed for providing full-text search for your Perl objects with Swish-e.

Since SWISH::Prog::Object inherits from SWISH::Prog, read the SWISH::Prog docs first. Any overridden methods are documented here.

If it seems odd at first to think of indexing objects, consider the advantages:

sorting

Particularly for scalar method values, time for sorting objects by method value is greatly decreased thanks to Swish-e's pre-sorted properties.

SWISH::API::Object integration

If you use SWISH::API::Object, you can get a Storable-like freeze/thaw effect with SWISH::Prog::Object.

caching

If some methods in your objects take a long while to calculate values, but don't change often, you can use Swish-e to cache those values, similar to the Cache::* modules, but in a portable, fast index.

METHODS

new( class => classname, methods => array ref of method names to call )

Create new indexer object.

NOTE: The new() method simply inherits from SWISH::Prog, so any params valid for that method() are allowed here.

methods

The methods param takes an array ref of method names. Each method name will be called on each object in create(). Each method name will also be stored as a PropertyName in the Swish-e index.

If not specified, a simple Symbol table lookup will be done on class and all non-built-in methods will be used by default.

class

The name of the class each object belongs to. The class value will be stored in the index itself for later use with SWISH::API::Object (or for your own amusement).

If not specified, defaults to SWISH::Prog::Object::Doc::Instance.

title

Which method to use as the swishtitle value. Defaults to title.

url

Which method to use as the swishdocpath value. Defaults to url.

modtime

Which method to use as the swishlastmodified value. Defaults to Perl built-in time().

init

Initialize object. This overrides SWISH::Prog init() base method.

init_indexer

Adds the PropertyNames for each of methods. The special PropertyNamesNoStripChars config option is used so that all whitespace etc is preserved verbatim.

Each method is also configured as a MetaName. A top level MetaName using the classname value is also configured.

create( data )

Index your objects.

data should either be an array ref of objects, or an iterator object with two methods: done and next. If data is an iterator, it will be used like:

 until($data->done)
 {
     $indexer->deal_with( $data->next );
 }
 

Returns number of objects indexed.

obj2xml( class, object, title )

Returns object as an XML string.

obj_filter( object )

Override this method if you need to alter the object data prior to being indexed.

This method is called prior to title_filter() so all object data is affected.

NOTE: This is different from the obj() method in the ::Doc subclass. This obj_filter() gets called before the Doc object is created.

title_filter( object )

Override this method if you do not provide a title param in new() or if you have no title method to call on object.

The return value of title_filter() will be used as the swishtitle for the object's virtual XML document.

REQUIREMENTS

SWISH::Prog, Data::Dump

LIMITATIONS and BUGS

SWISH::Prog::Object cannot index method values that are not scalars, array refs or hash refs, due to how reference values stringify with Data::Dump.

SEE ALSO

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

SWISH::Prog, SWISH::API:Object

AUTHOR

Peter Karman, <perl@peknet.com>

Thanks to Atomic Learning for supporting 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.