View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Eric Wilhelm > dotReader-v0.11.2 > dtRdr::Search::Book



Annotate this POD


New  2
Open  1
View/Report Bugs


dtRdr::Search::Book - Search a book


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


  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 ^


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


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



Methods ^


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.)




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


Returns the node which is currently being searched.

  my $node = $self->_node;


Eric Wilhelm <ewilhelm at cpan dot org>


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


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.


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: