blib/lib/App/Prove/Elasticsearch/Utils.pm

filter: Statementstmt 95.6% 87 / 91 Branchbran 77.2% 17 / 22 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 17 / 17 Podpod 100% 12 / 12 totaltotal 91.3% 138 / 151 CC 17 SCAR 13.4
CC
17
Cov
91%
process_configuration
9.1
require_provisioner
4.1
require_indexer
3.0
CRAP 3.8
« blib/lib/App/Prove/Elasticsearch/Queue/Default.pm ↑ Summary blib/lib/App/ape/update.pm »
1 # PODNAME: App::Prove::Elasticsearch::Utils
2 # ABSTRACT: common functions used by multiple modules in the distribution.
3  
4 package App::Prove::Elasticsearch::Utils;
5 30 $App::Prove::Elasticsearch::Utils::VERSION = '0.001';
6 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 ▶use Config::Simple();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 30 ▶use File::HomeDir();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶sub process_configuration {
Subroutine process_configuration: called CC=8 SCAR=22.1
Pod documented
13 3 my $args = shift;
14 3 my $conf = {};
15  
16 3 ▶ my $homedir = File::HomeDir::my_home() || '.';
Condition50%1/2
File::HomeDir::my_home() || '.'
l!l
30
MC/DC0%0/1
File::HomeDir::my_home() || '.'
File::HomeDir::my_home()
Truth table50%1/2
A
A= File::HomeDir::my_home()
Aresult
11
00
17 3 ▶ if (-e $homedir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $homedir) 2 1 3
18 2 ▶ unless (Config::Simple->import_from("$homedir/elastest.conf", $conf)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Config::Simple"->import_from("$homedir/elastest.conf", $conf)) 0 2 2
19 0 ▶ warn Config::Simple->error() if -e "$homedir/elastest.conf";
Branch: 1 branch
BranchTrueFalseTotal
if -e "$homedir/elastest.conf" 0 0 0
20 }
21 }
22  
23 3 my @kvp = ();
24 3 my ($key, $value);
25 3 foreach my $arg (@$args) {
26 4 @kvp = split(/=/, $arg);
27 4 ▶ if (scalar(@kvp) < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @kvp < 2) 0 4 4
28 0 print
29 "Unrecognized Argument '$arg' to App::Prove::Plugin::Elasticsearch, ignoring\n";
30 0 next;
31 }
32 4 $key = shift @kvp;
33 4 $value = join('', @kvp);
34 4 $conf->{$key} = $value;
35 }
36  
37 #Set ENV for use by harness
38 3 foreach my $key (keys(%$conf)) {
39 6 my $km = uc($key);
40 6 $km =~ s/\./_/g;
41 6 $ENV{$km} = $conf->{$key};
42 }
43  
44 3 return $conf;
45 }
46  
47 3 ▶sub require_indexer {
Subroutine require_indexer: called CC=3 SCAR=11.0
Pod documented
48 3 my $conf = shift;
49 my $index_suffix =
50 3 ▶ $conf->{'client.indexer'} ? "::" . $conf->{'client.indexer'} : '';
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'client.indexer'} ? : 1 2 3
51 3 my $indexer = "App::Prove::Elasticsearch::Indexer$index_suffix";
52  
53 3 eval "require $indexer";
54 3 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 2 3
55  
56 #Set ENV for use by harness
57 2 $ENV{CLIENT_INDEXER} = $indexer;
58 2 return $indexer;
59 }
60  
61 1 ▶sub require_searcher {
Subroutine require_searcher: called CC=1 SCAR=0.0
Pod documented
62 1 my $conf = shift;
63 1 return _require_generic(
64 $conf,
65 'App::Prove::Elasticsearch::Searcher',
66 'client.autodiscover',
67 'CLIENT_AUTODISCOVER'
68 );
69 }
70  
71 2 ▶sub require_blamer {
Subroutine require_blamer: called CC=1 SCAR=0.0
Pod documented
72 2 my $conf = shift;
73 2 return _require_generic(
74 $conf,
75 'App::Prove::Elasticsearch::Blamer',
76 'client.blamer',
77 'CLIENT_BLAMER'
78 );
79 }
80  
81 2 ▶sub require_planner {
Subroutine require_planner: called CC=1 SCAR=0.0
Pod documented
82 2 my $conf = shift;
83 2 return _require_generic(
84 $conf,
85 'App::Prove::Elasticsearch::Planner',
86 'client.planner',
87 'CLIENT_PLANNER'
88 );
89 }
90  
91 2 ▶sub require_platformer {
Subroutine require_platformer: called CC=1 SCAR=0.0
Pod documented
92 2 my $conf = shift;
93 2 return _require_generic(
94 $conf,
95 'App::Prove::Elasticsearch::Platformer',
96 'client.platformer',
97 'CLIENT_PLATFORMER'
98 );
99 }
100  
101 2 ▶sub require_queue {
Subroutine require_queue: called CC=1 SCAR=0.0
Pod documented
102 2 my $conf = shift;
103 2 return _require_generic(
104 $conf,
105 'App::Prove::Elasticsearch::Queue',
106 'client.queue',
107 'CLIENT_QUEUE'
108 );
109 }
110  
111 2 ▶sub require_versioner {
Subroutine require_versioner: called CC=1 SCAR=0.0
Pod documented
112 2 my $conf = shift;
113 2 return _require_generic(
114 $conf,
115 'App::Prove::Elasticsearch::Versioner',
116 'client.versioner',
117 'CLIENT_VERSIONER'
118 );
119 }
120  
121 2 ▶sub require_runner {
Subroutine require_runner: called CC=1 SCAR=0.0
Pod documented
122 2 my $conf = shift;
123 2 return _require_generic(
124 $conf,
125 'App::Prove::Elasticsearch::Runner',
126 'client.runner',
127 'CLIENT_RUNNER'
128 );
129 }
130  
131 2 ▶sub require_provisioner {
Subroutine require_provisioner: called CC=4 SCAR=14.2
Pod documented
132 2 my $module = shift;
133 2 ▶ $module //= 'Default';
Condition50%1/2
$module //= "Default"
l!l
20
MC/DC0%0/1
$module //= "Default"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
134 2 my $module_full = "App::Prove::Elasticsearch::Provisioner::$module";
135 2 eval "require $module_full";
136 2 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 1 2
137  
138 #Set ENV for use by harness
139 1 ▶ if ($ENV{CLIENT_PROVISIONERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'CLIENT_PROVISIONERS'}) { } 0 1 1
140 0 $ENV{CLIENT_PROVISIONERS} .= ":$module_full";
141 } else {
142 1 $ENV{CLIENT_PROVISIONERS} = "$module_full";
143 }
144 1 return $module_full;
145 }
146  
147 13 ▶sub _require_generic {
Subroutine _require_generic: called CC=3 SCAR=11.0
148 13 my ($conf, $prefix, $suffix_key, $envvar) = @_;
149 13 ▶ my $suffix = $conf->{$suffix_key} // 'Default';
Condition100%2/2
$conf->{$suffix_key} // "Default"
l!l
67
MC/DC100%1/1
$conf->{$suffix_key} // "Default"
$conf->{$suffix_key}
Truth table100%2/2
A
A= $conf->{$suffix_key}
Aresult
11
00
150 13 my $module = "${prefix}::$suffix";
151  
152 13 eval "require $module";
153 13 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 7 6 13
154  
155 #Set ENV for use by harness
156 6 $ENV{$envvar} = $suffix;
157 6 return $module;
158 }
159  
160 2 ▶sub get_last_index {
Subroutine get_last_index: called CC=2 SCAR=6.9
Pod documented
161 2 my ($e, $index) = @_;
162  
163 2 my $res = $e->search(
164 index => $index,
165 body => {
166 query => {match_all => {}},
167 sort => {id => {order => "desc"}},
168 size => 1
169 }
170 );
171  
172 2 my $hits = $res->{hits}->{hits};
173 2 ▶ return 0 unless scalar(@$hits);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$hits 1 1 2
174  
175 1 return $res->{hits}->{total};
176 }
177  
178 6 ▶sub do_paginated_query {
Subroutine do_paginated_query: called CC=2 SCAR=6.9
Pod documented
179 6 my ($e, $max_query_size, %q) = @_;
180 6 my $offset = 0;
181 6 my $hits = [];
182 6 my $hitcounter = $max_query_size;
183 6 ▶ while ($hitcounter == $max_query_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hitcounter == $max_query_size) 6 6 12
184 6 $q{size} = $max_query_size;
185 6 $q{from} = ($max_query_size * $offset);
186 6 my $res = $e->search(%q);
187 6 push(@$hits, @{$res->{hits}->{hits}});
188 6 $hitcounter = scalar(@{$res->{hits}->{hits}});
189 6 $offset++;
190 }
191 6 return $hits;
192 }
193  
194 30 1;
195  
196 __END__
« blib/lib/App/Prove/Elasticsearch/Queue/Default.pm ↑ Summary blib/lib/App/ape/update.pm »