GIN/Driver/Hash.pm

filter: Statementstmt 80.3% 49 / 61 Branchbran 40.0% 4 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 4 totaltotal 72.0% 67 / 93 CC 9 SCAR 12.0
CC
9
Cov
74%
remove_ids
7.7
insert_entry
4.0
fetch_entry
2.1
CRAP 3.3
« GIN/Driver.pm ↑ Summary GIN/Query/Attributes.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::Hash;
4  
5 4 our $VERSION = '0.11';
6  
7 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Set::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Data::Stream::Bulk::Util qw(bulk);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 with qw(Search::GIN::Driver);
14  
15 has values => (
16 isa => "HashRef",
17 is => "ro",
18 4 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 4 );
20  
21 has objects => (
22 isa => "HashRef",
23 is => "ro",
24 4 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 4 );
26  
27 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my $self = shift;
29  
30 0 %{ $self->values } = ();
31 0 %{ $self->objects } = ();
32  
33 0 return;
34 }
35  
36 15 ▶sub fetch_entry {
Subroutine fetch_entry: called CC=2 SCAR=7.6
Pod undocumented
37 15 my ( $self, $key ) = @_;
38  
39 15 ▶ if ( my $set = $self->values->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $set = $self->values->{$key}) { } 15 0 15
40 15 return bulk($set->members);
41 } else {
42 0 return;
43 }
44 }
45  
46 16 ▶sub remove_ids {
Subroutine remove_ids: called CC=5 SCAR=20.4
Pod undocumented
47 16 my ( $self, @ids ) = @_;
48  
49 16 my $values = $self->values;
50 16 my $objects = $self->objects;
51  
52 16 ▶ my @key_sets = grep { defined } delete @{$objects}{map { ref() ? refaddr($_) : $_ } @ids};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 16 0 16
53 16 ▶ return unless @key_sets;
Branch: 1 branch
BranchTrueFalseTotal
unless @key_sets 16 0 16
54 0 my $keys = (shift @key_sets)->union(@key_sets);
55  
56 0 foreach my $key ( $keys->members ) {
57 0 my $set = $values->{$key};
58 0 $set->remove(@ids);
59 0 ▶ delete $values->{$key} if $set->size == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $set->size == 0 0 0 0
60 }
61 }
62  
63 16 ▶sub insert_entry {
Subroutine insert_entry: called CC=4 SCAR=14.0
Pod undocumented
64 16 my ( $self, $id, @keys ) = @_;
65  
66 16 my $values = $self->values;
67 16 my $objects = $self->objects;
68  
69 16 $self->remove_ids($id);
70  
71 16 ▶ my $set = $objects->{ref($id) ? refaddr($id) : $id} = Set::Object->new;
Branch: 1 branch
BranchTrueFalseTotal
ref $id ? : 16 0 16
72  
73 16 $set->insert(@keys);
74  
75 16 foreach my $id_set (@{$values}{@keys}) {
76 45 ▶ $id_set ||= Set::Object->new;
Condition66%2/3
$id_set ||= "Set::Object"->new
l!l&&r!l&&!r
20250
MC/DC0%0/2
$id_set ||= "Set::Object"->new
$id_set "Set::Object"->new
Truth table66%2/3
A ||= B
A= $id_setB= "Set::Object"->new
ABresult
1X1
011
000
77 45 $id_set->insert($id);
78 }
79 }
80  
81 4 1;
« GIN/Driver.pm ↑ Summary GIN/Query/Attributes.pm »