| 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'
MC/DC100%1/1
$args{'method'} || 'any'
$args{'method'}
Truth table100%2/2
A
A= $args{'method'}
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 54 | 9 | ▶ | return $streams[0] if @streams == 1; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | |||||||||||||
| 56 | 1 | foreach my $stream ( @streams ) { | |||||||||||
| 57 | 2 | ▶ | return cat(splice @streams) unless $stream->loaded; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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; | |||||||||||