GIN/Driver.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 70.0% 7 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 4 totaltotal 89.3% 67 / 75 CC 10 SCAR 13.0
CC
10
Cov
93%
fetch_entries_all
7.0
fetch_entries_any
3.2
fetch_entries
2.0
CRAP 3.7
« GIN/Query/Class.pm ↑ Summary GIN/Driver/Hash.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Search::GIN::Driver;
4  
5 4 our $VERSION = '0.11';
6  
7 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Data::Stream::Bulk::Util qw(bulk nil cat unique);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 requires qw(
12 insert_entry
13 remove_ids
14 fetch_entry
15 );
16  
17 14 ▶sub fetch_entry_streams {
Subroutine fetch_entry_streams: called CC=1 SCAR=0.0
Pod undocumented
18 14 my ( $self, %args ) = @_;
19 14 map { $self->fetch_entry($_) } @{ $args{values} };
20 }
21  
22 14 ▶sub fetch_entries {
Subroutine fetch_entries: called CC=2 SCAR=6.9
Pod undocumented
23 14 my ( $self, %args ) = @_;
24  
25 14 ▶ my $method = "fetch_entries_" . ( $args{method} || "any" );
Condition100%2/2
$args{'method'} || 'any'
l!l
104
MC/DC100%1/1
$args{'method'} || 'any'
$args{'method'}
Truth table100%2/2
A
A= $args{'method'}
Aresult
11
00
26  
27 14 $self->$method(%args);
28 }
29  
30 4 ▶sub fetch_entries_any {
Subroutine fetch_entries_any: called CC=3 SCAR=11.6
Pod undocumented
31 4 my ( $self, @args ) = @_;
32  
33 4 my @streams = $self->fetch_entry_streams(@args);
34  
35 4 ▶ return nil unless @streams;
Branch: 1 branch
BranchTrueFalseTotal
unless @streams 0 4 4
36  
37 4 my $res = cat(splice @streams); # splice disposes of @streams ASAP, keeping memory utilization down
38  
39 4 ▶ if ( $res->loaded ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->loaded) { } 4 0 4
40 # if all results are already ready, we can uniqify them to avoid
41 # duplicate calls to ->consistent
42 4 return unique($res);
43 } else {
44 0 return $res;
45 }
46 }
47  
48 10 ▶sub fetch_entries_all {
Subroutine fetch_entries_all: called CC=7 SCAR=19.5
Pod undocumented
49 10 my ( $self, @args ) = @_;
50  
51 10 my @streams = $self->fetch_entry_streams(@args);
52  
53 10 ▶ return nil unless @streams;
Branch: 1 branch
BranchTrueFalseTotal
unless @streams 1 9 10
54 9 ▶ return $streams[0] if @streams == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @streams == 1 8 1 9
55  
56 1 foreach my $stream ( @streams ) {
57 2 ▶ return cat(splice @streams) unless $stream->loaded;
Branch: 1 branch
BranchTrueFalseTotal
unless $stream->loaded 0 2 2
58 }
59  
60 # if we made it to here then we have a > 1 list of fully realized streams
61 # we can compute the intersection of the IDs to avoid unnecessary calls to
62 # ->consistent
63  
64 # If all streams are known to be sorted this method could be overridden to
65 # use merge sorting
66  
67 1 my $last = shift @streams;
68 1 my $n = scalar @streams;
69  
70 # compute intersection
71 1 my %seen;
72 1 foreach my $stream ( splice @streams ) {
73 1 ++$seen{$_} for $stream->all;
74 }
75  
76 4 ▶ no warnings 'uninitialized'; # == with undef
Subroutine BEGIN: called CC=1 SCAR=0.0
77 1 return bulk( grep { $seen{$_} == $n } $last->all );
78 }
79  
80 4 1;
« GIN/Query/Class.pm ↑ Summary GIN/Driver/Hash.pm »