Model/SearchBuilder.pm

filter: Statementstmt 70.8% 34 / 48 Branchbran 32.1% 9 / 28 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 58.8% 10 / 17 Podpod n/a totaltotal 56.2% 54 / 96 CC 17 SCAR 27.9
CC
17
Cov
56%
_refkind
31.2
_uid_to_terms
20.0
_hashpair_ElasticDocREF
2.0
CRAP 16.3
« Model/0_90/Store.pm ↑ Summary Model/Role/Doc.pm »
1 package Elastic::Model::SearchBuilder;
2 11 $Elastic::Model::SearchBuilder::VERSION = '0.52';
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use ElasticSearch::SearchBuilder 0.18;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use parent 'ElasticSearch::SearchBuilder';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #===================================
10 0 ▶sub _hashpair_ElasticDocREF {
Subroutine _hashpair_ElasticDocREF: not called CC=1 SCAR=6.9
11 #===================================
12 0 my ( $self, $type, $k, $v ) = @_;
13 0 $self->_uid_to_terms( $type, $k, $v->uid );
14 }
15  
16 #===================================
17 0 ▶sub _hashpair_ElasticUIDREF {
Subroutine _hashpair_ElasticUIDREF: not called CC=1 SCAR=6.9
18 #===================================
19 0 my ( $self, $type, $k, $v ) = @_;
20 0 $self->_uid_to_terms( $type, $k, $v );
21 }
22  
23 #===================================
24 123 ▶sub _filter_field_terms {
Subroutine _filter_field_terms: called CC=1 SCAR=0.6
25 #===================================
26 123 my ( $self, $k, $op, $val ) = @_;
27  
28 return $self->_SWITCH_refkind(
29 "Filter field operator -$op",
30 $val,
31 { ElasticDocREF =>
32 0 ▶ sub { $self->_uid_to_terms( 'filter', $k, $val->uid ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 ElasticUIDREF =>
34 0 ▶ sub { $self->_uid_to_terms( 'filter', $k, $val ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 123 ▶ FALLBACK => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
36 123 $self->SUPER::_filter_field_terms( $k, $op, $val );
37 },
38 }
39 123 );
40 }
41  
42 #===================================
43 108 ▶sub _query_field_match {
Subroutine _query_field_match: called CC=1 SCAR=0.4
44 #===================================
45 108 my $self = shift;
46 108 my ( $k, $op, $val ) = @_;
47  
48 return $self->_SWITCH_refkind(
49 "Query field operator -$op",
50 $val,
51 { ElasticDocREF =>
52 0 ▶ sub { $self->_uid_to_terms( 'query', $k, $val->uid ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 ElasticUIDREF =>
54 0 ▶ sub { $self->_uid_to_terms( 'query', $k, $val ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 108 ▶ FALLBACK => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
56 108 $self->SUPER::_query_field_match( $k, $op, $val );
57 },
58 }
59 108 );
60 }
61  
62 #===================================
63 0 ▶sub _uid_to_terms {
Subroutine _uid_to_terms: not called CC=4 SCAR=30.0
64 #===================================
65 0 my ( $self, $type, $k, $uid ) = @_;
66 0 my @clauses;
67 0 for (qw(index type id)) {
68 0 ▶ my $val = $uid->$_ or croak "UID missing ($_)";
Branch: 1 branch
BranchTrueFalseTotal
my $val = $uid->$_ or croak("UID missing ($_)") 0 0 0
69 0 push @clauses, { term => { "${k}.uid.$_" => $val } };
70 }
71 0 ▶ return $type eq 'query'
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'query' ? : 0 0 0
72 ? { bool => { must => \@clauses } }
73 : { and => \@clauses }
74  
75 }
76  
77 #===================================
78 4174 ▶sub _refkind {
Subroutine _refkind: called CC=14 SCAR=34.4
79 #===================================
80 4174 my ( $self, $data ) = @_;
81  
82 4174 ▶ return 'UNDEF' unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 275 3899 4174
83  
84 3899 ▶ my $ref
Branch: 4 branches
BranchTrueFalseTotal
!builtin::blessed($data) ? : 3899 0 3899
!$data->can('does') ? : 0 0 0
$data->does('Elastic::Model::Role::Doc') ? : 0 0 0
$data->isa('Elastic::Model::UID') ? : 0 0 0
85 = !Scalar::Util::blessed($data) ? ref $data
86 : !$data->can('does') ? ''
87 : $data->does('Elastic::Model::Role::Doc') ? 'ElasticDoc'
88 : $data->isa('Elastic::Model::UID') ? 'ElasticUID'
89 : '';
90  
91 3899 ▶ return 'SCALAR' unless $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 1107 2792 3899
92  
93 2792 my $n_steps = 1;
94 2792 ▶ while ( $ref eq 'REF' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq "REF") 6 2792 2798
95 6 $data = $$data;
96 6 ▶ $ref
Branch: 4 branches
BranchTrueFalseTotal
!builtin::blessed($data) ? : 6 0 6
!$data->can('does') ? : 0 0 0
$data->does('Elastic::Model::Role::Doc') ? : 0 0 0
$data->isa('Elastic::Model::UID') ? : 0 0 0
97 = !Scalar::Util::blessed($data) ? ref $data
98 : !$data->can('does') ? ''
99 : $data->does('Elastic::Model::Role::Doc') ? 'ElasticDoc'
100 : $data->isa('Elastic::Model::UID') ? 'ElasticUID'
101 : '';
102 6 ▶ $n_steps++ if $ref;
Branch: 1 branch
BranchTrueFalseTotal
if $ref 6 0 6
103 }
104  
105 2792 ▶ return ( $ref || 'SCALAR' ) . ( 'REF' x $n_steps );
Condition50%1/2
$ref || 'SCALAR'
l!l
27920
MC/DC0%0/1
$ref || 'SCALAR'
$ref
Truth table50%1/2
A
A= $ref
Aresult
11
00
106 }
107  
108 11 1;
109  
110 # ABSTRACT: An Elastic::Model specific subclass of L<ElasticSearch::SearchBuilder>
111  
112 __END__
« Model/0_90/Store.pm ↑ Summary Model/Role/Doc.pm »