| 1 | # | ||||||||||||||||||||||||||||
| 2 | # This file is part of ElasticSearchX-Model | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2019 by Moritz Onken. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # The (three-clause) BSD License | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | package ElasticSearchX::Model::Trait::Class; | ||||||||||||||||||||||||||||
| 11 | 12 | $ElasticSearchX::Model::Trait::Class::VERSION = '2.0.1'; | |||||||||||||||||||||||||||
| 12 | 12 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use List::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 48 | ▶ | sub _handles { | ||||||||||||||||||||||||||
|
Subroutine
_handles: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 48 | my ( $s, $p ) = @_; | |||||||||||||||||||||||||||
| 18 | return { | ||||||||||||||||||||||||||||
| 19 | 48 | "get_$s" => 'get', | |||||||||||||||||||||||||||
| 20 | "get_$p" => 'values', | ||||||||||||||||||||||||||||
| 21 | "get_${s}_list" => 'keys', | ||||||||||||||||||||||||||||
| 22 | "remove_$s" => 'delete', | ||||||||||||||||||||||||||||
| 23 | "add_$s" => 'set', | ||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 12 | my %foo = ( | |||||||||||||||||||||||||||
| 27 | analyzer => 'analyzers', | ||||||||||||||||||||||||||||
| 28 | tokenizer => 'tokenizers', | ||||||||||||||||||||||||||||
| 29 | filter => 'filters' | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | 12 | ▶ | while ( my ( $s, $p ) = each %foo ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | has $p => ( | ||||||||||||||||||||||||||||
| 33 | traits => ['Hash'], | ||||||||||||||||||||||||||||
| 34 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 35 | 36 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 36 | handles => _handles( $s, $p ) | |||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | has indices => ( | ||||||||||||||||||||||||||||
| 41 | traits => ['Hash'], | ||||||||||||||||||||||||||||
| 42 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 43 | 12 | ▶ | default => sub { { default => {} } }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 12 | handles => _handles( 'index', 'indices' ) | |||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 12 | ▶ | before add_index => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 48 | 12 | my ( $self, $name, $index ) = @_; | |||||||||||||||||||||||||||
| 49 | 12 | $self->remove_index('default'); | |||||||||||||||||||||||||||
| 50 | 12 | ▶ | if ( $index->{alias_for} && $name ne $index->{alias_for} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$index->{"alias_for"} and $name ne $index->{"alias_for"}
MC/DC100%2/2
$index->{"alias_for"} and $name ne $index->{"alias_for"}
$index->{"alias_for"}
$name ne $index->{"alias_for"}
Truth table100%3/3
A and B
A= $index->{"alias_for"}B= $name ne $index->{"alias_for"}
| |||||||||||||||||||||||||||||
| 51 | 1 | return $self->add_index( $index->{alias_for}, $index ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 12 | }; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 12 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||