File Coverage

blib/lib/KinoSearch1/Index/SegTermEnum.pm
Criterion Covered Total %
statement 42 46 91.3
branch 1 4 25.0
condition n/a
subroutine 12 13 92.3
pod 1 5 20.0
total 56 68 82.3


line stmt bran cond sub pod time code
1             package KinoSearch1::Index::SegTermEnum;
2 34     34   214 use strict;
  34         67  
  34         1083  
3 34     34   860 use warnings;
  34         63  
  34         815  
4 34     34   176 use KinoSearch1::Util::ToolSet;
  34         75  
  34         4686  
5 34     34   186 use base qw( KinoSearch1::Util::Class );
  34         133  
  34         3188  
6              
7             BEGIN {
8 34     34   306 __PACKAGE__->init_instance_vars(
9             # constructor params
10             finfos => undef,
11             instream => undef,
12             is_index => 0,
13             );
14             }
15             our %instance_vars;
16              
17 34     34   17764 use KinoSearch1::Index::Term;
  34         94  
  34         814  
18 34     34   19555 use KinoSearch1::Index::TermInfo;
  34         100  
  34         815  
19 34     34   18444 use KinoSearch1::Index::TermBuffer;
  34         93  
  34         12982  
20              
21             sub new {
22             # verify params
23 208     208 1 360 my $ignore = shift;
24 208         1087 my %args = ( %instance_vars, @_ );
25 208 50       874 confess kerror() unless verify_args( \%instance_vars, %args );
26              
27             # get a TermBuffer helper object
28 208         1439 my $term_buffer
29             = KinoSearch1::Index::TermBuffer->new( finfos => $args{finfos}, );
30              
31 208         4134 return _new_helper( @args{ 'instream', 'is_index', 'finfos', },
32             $term_buffer );
33             }
34              
35             sub clone_enum {
36 17     17 0 40 my $self = shift;
37              
38             # dupe instream and seek it to the start of the file, so init works right
39 17         68 my $instream = $self->_get_instream;
40 17         96 my $new_stream = $instream->clone_stream;
41 17         76 $new_stream->seek(0);
42              
43             # create a new object and seek it to the right term/terminfo
44 17         165 my $evil_twin = __PACKAGE__->new(
45             finfos => $self->_get_finfos,
46             instream => $new_stream,
47             is_index => $self->is_index,
48             );
49 17         215 $evil_twin->seek(
50             $instream->tell, $self->_get_position,
51             $self->get_termstring, $self->get_term_info
52             );
53 17         124 return $evil_twin;
54             }
55              
56             # Locate the Enum to a particular spot.
57             sub seek {
58 2040     2040 0 5599 my ( $self, $pointer, $position, $termstring, $tinfo ) = @_;
59              
60             # seek the filehandle
61 2040         5670 my $instream = $self->_get_instream;
62 2040         5715 $instream->seek($pointer);
63              
64             # set values as if we'd scanned here from the start of the Enum
65 2040         5248 $self->_set_position($position);
66 2040         5872 $self->_set_termstring($termstring);
67 2040         17697 $self->_set_term_info($tinfo);
68             }
69              
70             sub close {
71 78     78 0 309 my $instream = $_[0]->_get_instream;
72 78         209 $instream->close;
73             }
74              
75             # return a Term, if the Enum is currently valid.
76             sub get_term {
77 0     0 0   my $self = shift;
78 0           my $termstring = $self->get_termstring;
79 0 0         return unless defined $termstring;
80 0           return KinoSearch1::Index::Term->new_from_string( $termstring,
81             $self->_get_finfos );
82             }
83              
84             1;
85              
86             __END__