blib/lib/Catmandu/Hits.pm

filter: Statementstmt 100% 36 / 36 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 14.2% 1 / 7 totaltotal 88.8% 48 / 54 CC 2 SCAR 1.5
CC
2
Cov
100%
each
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/Catmandu/Buffer.pm ↑ Summary blib/lib/Catmandu/ArrayIterator.pm »
1 package Catmandu::Hits;
2  
3 14 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 14 our $VERSION = '1.0201_02';
6  
7 14 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 14 has start => (is => 'ro', required => 1);
11 14 has limit => (is => 'ro', required => 1);
12 14 has total => (is => 'ro', required => 1);
13 14 has hits => (is => 'ro', required => 1);
14  
15 14 with 'Catmandu::Iterable';
16 14 with 'Catmandu::Paged';
17  
18 sub size {
19 1 ▶ scalar @{$_[0]->hits};
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
20 }
21  
22 sub more {
23 1 ▶ my $self = $_[0];
Subroutine more: called CC=1 SCAR=0.0
Pod documented
24 1 $self->start + $self->limit < $self->total;
25 }
26  
27 sub generator {
28 1 ▶ my $self = $_[0];
Subroutine generator: called CC=1 SCAR=0.0
Pod undocumented
29 1 my $hits = $self->hits;
30 1 my $i = 0;
31 sub {
32 1 ▶ $hits->[$i++];
Subroutine __ANON__: called CC=1 SCAR=0.0
33 1 };
34 }
35  
36 sub to_array {
37 1 ▶ [@{$_[0]->hits}];
Subroutine to_array: called CC=1 SCAR=0.0
Pod undocumented
38 }
39  
40 sub count {
41 1 ▶ scalar @{$_[0]->hits};
Subroutine count: called CC=1 SCAR=0.0
Pod undocumented
42 }
43  
44 sub each {
45 1 ▶ my ($self, $cb) = @_;
Subroutine each: called CC=2 SCAR=6.9
Pod undocumented
46 1 my $hits = $self->hits;
47 1 for my $hit (@$hits) {
48 100 $cb->($hit);
49 }
50 1 $self->count;
51 }
52  
53 sub first {
54 1 ▶ $_[0]->hits->[0];
Subroutine first: called CC=1 SCAR=0.0
Pod undocumented
55 }
56  
57 14 1;
58  
59 __END__
60  
61 =pod
62  
63 =head1 NAME
64  
65 Catmandu::Hits - Iterable object that wraps Catmandu::Store search hits
66  
67 =head1 SYNOPSIS
68  
69 my $store = Catmandu::Store::Solr->new;
70  
71 my $hits = $store->bag->search(
72 query => 'dna' ,
73 start => 0 ,
74 limit => 100 ,
75 sort => 'title desc',
76 );
77  
78 # Every hits is an iterator...
79 $hits->each(sub { ... });
80  
81 printf "Found %s $hits\n" , $hits->total;
82  
83 my $start = $hits->start;
84 my $limit = $hits->limit;
85  
86 my $prev = $hits->previous_page;
87 my $next = $hits->next_page;
88  
89 =head1 METHODS
90  
91 A Catmandu::Hits object provides the following methods in addition to
92 methods of L<Catmandu::Iterable> and L<Catmandu::Paged>.
93  
94 =head2 total
95  
96 Returns the total number of hits matching the query.
97  
98 =head2 start
99  
100 Returns the start index for the search results.
101  
102 =head2 limit
103  
104 Returns the maximum number of search results returned.
105  
106 =head2 more
107  
108 Return true if there are more search results.
109  
110 =head1 SEE ALSO
111  
112 L<Catmandu::Bag>, L<Catmandu::Searchable>, L<Catmandu::Store>
113  
114 =cut
« blib/lib/Catmandu/Buffer.pm ↑ Summary blib/lib/Catmandu/ArrayIterator.pm »