Model/Index.pm

filter: Statementstmt 65.7% 46 / 70 Branchbran 33.3% 2 / 6 Conditioncond 22.2% 2 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 53.8% 7 / 13 Podpod 0.0% 0 / 6 totaltotal 52.7% 58 / 110 SCAR 29.7
CC
11
Cov
59%
_deploy
20.0
delete
6.0
__ANON__
4.0
CRAP 19.4
« Model/Document/Attribute/Role/MappingParameters.pm ↑ Summary Model/Document/Role/Metaclass.pm »
1 package Elasticsearch::Model::Index;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Class::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 around BUILDARGS => sub {
7 12 ▶ my ($orig, $self) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
8 12 my %args = @_;
9 12 my $args = $self->$orig(@_);
10 12 my @deprecated_attributes = qw/shards replicas refresh_interval/;
11 12 for my $deprecated_attribute (@deprecated_attributes) {
12 warnings::warn("deprecated",
13 "$deprecated_attribute is deprecated; please use index_settings instead"
14 36 ▶ ) if defined $args->{$deprecated_attribute} and (not $ENV{TESTING_ELASTICSEARCH_MODEL} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{$deprecated_attribute} and not $ENV{"TESTING_ELASTICSEARCH_MODEL"} 9 27 36
Condition66%2/3
defined $args->{$deprecated_attribute} and not $ENV{"TESTING_ELASTICSEARCH_MODEL"}
!ll&&!rl&&r
0279
MC/DC50%1/2
defined $args->{$deprecated_attribute} and not $ENV{"TESTING_ELASTICSEARCH_MODEL"}
defined $args->{$deprecated_attribute} not $ENV{"TESTING_ELASTICSEARCH_MODEL"}
Truth table66%2/3
A and not(B)
A= defined $args->{$deprecated_attribute}B= not $ENV{"TESTING_ELASTICSEARCH_MODEL"}
ABresult
0X0
100
111
15 }
16 12 return $args;
17 1 };
18  
19 1 has namespace => (
20 is => 'ro',
21 isa => 'Maybe[Str]',
22 );
23  
24 1 has [qw/namespaced_name name/]=> (
25 is => 'ro',
26 isa => 'Str',
27 );
28  
29 1 has refresh_interval => (
30 is => 'ro',
31 isa => 'Str',
32 default => '1s',
33 );
34  
35 1 has [qw/
36 shards
37 replicas
38 /] => (
39 is => 'ro',
40 isa => 'Int',
41 default => 1,
42 );
43  
44 has index_settings => (
45 is => 'ro',
46 isa => 'HashRef',
47 0 ▶ default => sub {{}},
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 1 );
49  
50 1 has model => (
51 is => 'ro',
52 does => 'Elasticsearch::Model::Role',
53 required => 1,
54 handles => [qw(es document_namespace)],
55 );
56  
57 1 has type => (
58 is => 'ro',
59 isa => 'Str',
60 required => 1,
61 );
62  
63 1 has type_meta => (
64 is => 'ro',
65 isa => 'Object',
66 lazy => 1,
67 builder => '_build_type_meta',
68 );
69  
70 sub _build_type_meta {
71 3 ▶ my $self = shift;
Subroutine _build_type_meta: called CC=1 SCAR=0.0
72 3 my $type_class = $self->document_namespace . "::" . $self->type;
73 3 Class::Load::load_class($type_class);
74 3 return $type_class->meta;
75 }
76  
77 has traits => (
78 isa => 'ArrayRef',
79 is => 'ro',
80 12 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
81 1 );
82  
83 sub BUILD {
84 12 ▶ my $self = shift;
Subroutine BUILD: called CC=2 SCAR=7.1
Pod undocumented
85 12 foreach my $trait (@{$self->traits}) {
86 0 Moose::Util::ensure_all_roles($self, $trait);
87 }
88 12 return $self;
89 }
90  
91 sub deployment_statement {
92 3 ▶ my $self = shift;
Subroutine deployment_statement: called CC=3 SCAR=11.0
Pod undocumented
93 3 my $deploy = {};
94 3 $deploy->{mappings}{_doc} = $self->type_meta->mapping;
95 3 my $model_meta = $self->model->meta;
96 3 for (qw(filter analyzer tokenizer normalizer)) {
97 12 my $method = "get_${_}_list";
98 12 foreach my $name ($model_meta->$method) {
99 12 my $get = "get_$_";
100 12 $deploy->{settings}{analysis}{$_}{$name} =
101 $model_meta->$get($name);
102 }
103 }
104 $deploy->{settings}{index} = {
105 number_of_shards => $self->shards,
106 number_of_replicas => $self->replicas,
107 refresh_interval => $self->refresh_interval,
108 blocks => {
109 read_only_allow_delete => 'false',
110 },
111 3 %{$self->index_settings},
112 };
113  
114 3 return $deploy;
115 }
116  
117 sub _deploy {
118 0 ▶ my ($self, %args) = @_;
Subroutine _deploy: not called CC=4 SCAR=30.0
119 0 ▶ my $index_name = $args{index_name} // $self->namespaced_name;
Condition0%0/3
$args{"index_name"} // $self->namespaced_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"index_name"} // $self->namespaced_name
$args{"index_name"} $self->namespaced_name
Truth table0%0/3
A // B
A= $args{"index_name"}B= $self->namespaced_name
ABresult
1X1
011
000
120 0 my $delete = $args{delete};
121  
122 0 ▶ if ($delete) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delete) 0 0 0
123 0 $self->es->indices->delete(index => $index_name, ignore_unavailable => 'true');
124 }
125  
126 0 my $t = $self->es->transport;
127  
128 0 my $dep = $self->deployment_statement;
129 0 my $mapping = delete $dep->{mappings};
130  
131 # Settings, like analyzers and filters
132 0 $t->perform_request(
133 {
134 method => 'PUT',
135 path => "/$index_name",
136 body => $dep,
137 }
138 );
139 0 sleep(1);
140  
141 # Mappings, like whatever fields
142 0 ▶ while (my ($k, $v) = each %$mapping) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$mapping) 0 0 0
143 0 $t->perform_request(
144 {
145 method => 'PUT',
146 path => "/$index_name/$k/_mapping",
147 body => {$k => $v},
148 }
149 );
150 }
151 0 return 1;
152 }
153  
154 sub deploy {
155 0 ▶ my ($self, %args) = @_;
Subroutine deploy: not called CC=1 SCAR=6.9
Pod undocumented
156 0 $self->_deploy(%args);
157 }
158  
159 sub deploy_to {
160 0 ▶ my ($self, %args) = @_;
Subroutine deploy_to: not called CC=1 SCAR=6.9
Pod undocumented
161 0 $self->_deploy(%args);
162 }
163  
164 sub refresh {
165 0 ▶ my $self = shift;
Subroutine refresh: not called CC=1 SCAR=6.9
Pod undocumented
166 0 $self->es->indices->refresh(index => $self->namespaced_name, ignore_unavailable => 'true');
167 }
168  
169 sub delete {
170 0 ▶ my ($self, %args) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod undocumented
171 0 ▶ my $index_name = $args{index} // $self->namespaced_name;
Condition0%0/3
$args{"index"} // $self->namespaced_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"index"} // $self->namespaced_name
$args{"index"} $self->namespaced_name
Truth table0%0/3
A // B
A= $args{"index"}B= $self->namespaced_name
ABresult
1X1
011
000
172 0 $self->es->indices->delete(index => $index_name, ignore_unavailable => 'true');
173 }
174  
175 1 __PACKAGE__->meta->make_immutable;
176  
177 1 1;
« Model/Document/Attribute/Role/MappingParameters.pm ↑ Summary Model/Document/Role/Metaclass.pm »