File Coverage

blib/lib/Plucene/Search/PhrasePositions.pm
Criterion Covered Total %
statement 27 27 100.0
branch 4 4 100.0
condition 4 6 66.6
subroutine 7 7 100.0
pod 4 4 100.0
total 46 48 95.8


line stmt bran cond sub pod time code
1             package Plucene::Search::PhrasePositions;
2              
3             =head1 NAME
4              
5             Plucene::Search::PhrasePositions - The position of a phrase
6              
7             =head1 SYNOPSIS
8              
9             my $phpos = Plucene::Search::PhrasePositions->new;
10              
11             my $next = $phpos->next;
12             my $first_pos = $phpos->first_position;
13             my $next_pos = $phpos->next_position;
14            
15             =head1 DESCRIPTION
16              
17             =head1 METHODS
18              
19             =cut
20              
21 4     4   20 use strict;
  4         8  
  4         116  
22 4     4   20 use warnings;
  4         9  
  4         97  
23              
24 4     4   20 use base 'Class::Accessor::Fast';
  4         9  
  4         1345  
25              
26             __PACKAGE__->mk_accessors(qw/ doc position count offset tp next_in_list /);
27              
28             =head2 new
29              
30             my $phpos = Plucene::Search::PhrasePositions->new;
31              
32             Make a new Plucene::Search::PhrasePositions object.
33            
34             =head2 doc / position / count / offset / tp / next
35              
36             Get / set these attibutes.
37              
38             =cut
39              
40             sub new {
41 13     13 1 71 my $self = shift->SUPER::new(@_);
42 13   100     209 $self->{offset} ||= 0;
43 13   50     77 $self->{position} ||= 0;
44 13   50     77 $self->{count} ||= 0;
45 13         42 $self->next;
46 13         115 $self;
47             }
48              
49             =head2 next
50              
51             my $next = $phpos->next;
52              
53             =cut
54              
55             sub next {
56 147     147 1 696 my $self = shift;
57 147 100       551 if (!$self->{tp}->next) {
58 6         30 $self->doc(~0);
59 6         59 return;
60             }
61 141         489 $self->doc($self->tp->doc);
62 141         1556 $self->position(0);
63             }
64              
65             =head2 first_position
66              
67             my $first = $phpos->first_position;
68              
69             =cut
70              
71             sub first_position {
72 129     129 1 182 my $self = shift;
73 129         436 $self->count($self->tp->freq);
74 129         1549 $self->next_position;
75             }
76              
77             =head2 next_position
78              
79             my $next_pos = $phpos->next_position;
80              
81             =cut
82              
83             sub next_position {
84 521     521 1 2177 my $self = shift;
85 521 100       1862 return unless $self->{count}-- > 0;
86 460         1732 $self->position($self->tp->next_position - $self->offset);
87             }
88              
89             1;