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; }
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.
visible_nodes()
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.)
searcher()
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.
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);
$self->_init;
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.)
$self->quick_next;
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>
http://scratchcomputing.com/
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.
To install dtRdr, copy and paste the appropriate command in to your terminal.
cpanm
cpanm dtRdr
CPAN shell
perl -MCPAN -e shell install dtRdr
For more information on module installation, please visit the detailed CPAN module installation guide.