Eric Wilhelm > dotReader > dtRdr::Search::Book

Download:
dotReader-v0.11.2.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  1
View/Report Bugs
Source  

NAME ^

dtRdr::Search::Book - Search a book

ABOUT ^

This class lets you setup a search for a given book and then churns out results.

SYNOPSIS ^

  my $searcher = dtRdr::Search::Book->new(
    book => $book,
    find => qr/foo/i
  );

  while(my $res = $searcher->next) {
    # it might return null result
    $res->null and next;
    my $node = $res->start_node;
    my $sel = $res->selection;
    my $sel_node = $sel->node;
  }

Quick Search ^

The default behavior is to do a slow and careful search of the node characters for each node returned by the book's visible_nodes() method. Because this uses the book API, it is extremely generic, but depending on the book, may also be extremely slow.

To speed-up the process, we have a quick-search scheme which allows the book to eliminate all nodes which do not match.

If the book has a searcher() method, it should return a subref (maybe later we'll support and object there.)

The subref will be called again and again until it returns undef. It should return true or a dtRdr::TOC object until it is done. The thus-gathered TOC objects will be the only nodes searched more thoroughly.

Constructor ^

new

  my $search = dtRdr::Search::Book->new(
    book => $book,
    find => qr/foo/i
  );

new_result

XXX this, and the generation of the custom result class, should be provided by the dtRdr::Search base class.

  my $result = $self->new_result(%args);

_init

  $self->_init;

Methods ^

next

Perform the next search.

  my $result = $search->next;

Returns undef when done, and otherwise a dtRdr::Search::Result::Book object.

If $result->null is true, then nothing was found, but the end of the current node has been reached. This gives you a chance to do something else before diving into the next search. (If we didn't do it this way, searching a large book with no hits would block until it was completely done.)

quick_next

  $self->quick_next;

result_node

  my $orig_node = $self->result_node($range->node);

_node

Returns the node which is currently being searched.

  my $node = $self->_node;

AUTHOR ^

Eric Wilhelm <ewilhelm at cpan dot org>

http://scratchcomputing.com/

COPYRIGHT ^

Copyright (C) 2006 Eric L. Wilhelm and OSoft, All Rights Reserved.

NO WARRANTY ^

Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.

LICENSE ^

The dotReader(TM) is OSI Certified Open Source Software licensed under the GNU General Public License (GPL) Version 2, June 1991. Non-encrypted and encrypted packages are usable in connection with the dotReader(TM). The ability to create, edit, or otherwise modify content of such encrypted packages is self-contained within the packages, and NOT provided by the dotReader(TM), and is addressed in a separate commercial license.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

syntax highlighting: