blib/lib/ElasticSearchX/Model/Role.pm

filter: Statementstmt 37.5% 18 / 48 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 3 totaltotal 28.7% 23 / 80 CC 10 SCAR 38.3
CC
10
Cov
28%
deploy
90.0
_build_es
6.0
bulk
2.0
CRAP 46.2
↑ Summary blib/lib/ElasticSearchX/Model/Document/Trait/Class.pm »
1 #
2 # This file is part of ElasticSearchX-Model
3 #
4 # This software is Copyright (c) 2018 by Moritz Onken.
5 #
6 # This is free software, licensed under:
7 #
8 # The (three-clause) BSD License
9 #
10 package ElasticSearchX::Model::Role;
11 1 $ElasticSearchX::Model::Role::VERSION = '1.0.3';
12 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Search::Elasticsearch;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use ElasticSearchX::Model::Index;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use ElasticSearchX::Model::Document::Types qw(ES);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 has es => ( is => 'rw', lazy_build => 1, coerce => 1, isa => ES );
19  
20 sub _build_es {
21 Search::Elasticsearch->new(
22 0 ▶ nodes => $ENV{ES} || '127.0.0.1:9200',
Subroutine _build_es: not called CC=2 SCAR=17.9
Condition0%0/2
$ENV{'ES'} || '127.0.0.1:9200'
l!l
00
MC/DC0%0/1
$ENV{'ES'} || '127.0.0.1:9200'
$ENV{'ES'}
Truth table0%0/2
A
A= $ENV{'ES'}
Aresult
11
00
23 cxn => 'HTTPTiny',
24 );
25 }
26  
27 sub deploy {
28 0 ▶ my ( $self, %params ) = @_;
Subroutine deploy: not called CC=9 SCAR=45.0
Pod undocumented
29 0 my $t = $self->es->transport;
30  
31 0 foreach my $name ( $self->meta->get_index_list ) {
32 0 my $index = $self->index($name);
33 0 ▶ next if ( $index->alias_for && $name eq $index->alias_for );
Branch: 1 branch
BranchTrueFalseTotal
if $index->alias_for and $name eq $index->alias_for 0 0 0
Condition0%0/3
$index->alias_for and $name eq $index->alias_for
!ll&&!rl&&r
000
MC/DC0%0/2
$index->alias_for and $name eq $index->alias_for
$index->alias_for $name eq $index->alias_for
Truth table0%0/3
A and B
A= $index->alias_forB= $name eq $index->alias_for
ABresult
0X0
100
111
34 0 ▶ $name = $index->alias_for if ( $index->alias_for );
Branch: 1 branch
BranchTrueFalseTotal
if $index->alias_for 0 0 0
35 0 local $@;
36 0 eval { $self->es->indices->delete( index => $name ) }
37 0 ▶ if ( $params{delete} );
Branch: 1 branch
BranchTrueFalseTotal
if $params{"delete"} 0 0 0
38 0 my $dep = $index->deployment_statement;
39 0 my $mapping = delete $dep->{mappings};
40 0 eval {
41 0 $t->perform_request(
42 {
43 method => 'PUT',
44 path => "/$name",
45 body => $dep,
46 }
47 );
48 };
49 0 sleep(1);
50  
51 0 ▶ while ( my ( $k, $v ) = each %$mapping ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$mapping) 0 0 0
52 0 $t->perform_request(
53 {
54 method => 'PUT',
55 path => "/$name/$k/_mapping",
56 body => { $k => $v },
57 }
58 );
59 }
60 0 ▶ if ( my $alias = $index->alias_for ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $alias = $index->alias_for) 0 0 0
61 my @aliases = keys %{
62 0 ▶ $self->es->indices->get_aliases(
Branch: 1 branch
BranchTrueFalseTotal
$self->es->indices->get_aliases("index", $index->name, "ignore", [404]) or {} 0 0 0
63 index => $index->name,
64 ignore => [404]
65 )
66 || {}
67 };
68 my $actions = [
69 (
70 map {
71 0 { remove => { index => $_, alias => $index->name } }
72 } @aliases
73 ),
74 { add => { index => $alias, alias => $index->name } }
75 ];
76 0 $self->es->indices->update_aliases(
77 body => { actions => $actions } );
78 }
79 }
80 0 return 1;
81 }
82  
83 sub bulk {
84 0 ▶ my $self = shift;
Subroutine bulk: not called CC=1 SCAR=6.9
Pod undocumented
85 0 return ElasticSearchX::Model::Bulk->new( es => $self->es, @_ );
86 }
87  
88 sub es_version {
89 0 ▶ my $self = shift;
Subroutine es_version: not called CC=1 SCAR=6.9
Pod undocumented
90 0 my $string = $self->es->info->{version}->{number};
91 0 $string =~ s/RC//g;
92 0 return version->parse($string)->numify;
93 }
94  
95 1 1;
96  
97 __END__
98  
99 =pod
100  
101 =encoding UTF-8
102  
103 =head1 NAME
104  
105 ElasticSearchX::Model::Role
106  
107 =head1 VERSION
108  
109 version 1.0.3
110  
111 =head1 AUTHOR
112  
113 Moritz Onken
114  
115 =head1 COPYRIGHT AND LICENSE
116  
117 This software is Copyright (c) 2018 by Moritz Onken.
118  
119 This is free software, licensed under:
120  
121 The (three-clause) BSD License
122  
123 =cut
↑ Summary blib/lib/ElasticSearchX/Model/Document/Trait/Class.pm »