« blib/lib/ElasticSearchX/Model/Index.pm
↑ Summary
blib/lib/ElasticSearchX/Model/Document/Mapping.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::Document::Role; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | $ElasticSearchX::Model::Document::Role::VERSION = '1.0.3'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use Digest::SHA1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use ElasticSearchX::Model::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use List::MoreUtils (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub _does_elasticsearchx_model_document_role {1} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_does_elasticsearchx_model_document_role: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | has _inflated_attributes => | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | ( is => 'rw', isa => 'HashRef', lazy => 1, default => sub { {} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | has _loaded_attributes => ( | |||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | clearer => '_clear_loaded_attributes', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | has index => ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | isa => 'ElasticSearchX::Model::Index', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | has _id => ( | |||||||||||||||||||||||||||||||||||||||||
| 36 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | property => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | source_only => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | traits => [ | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 'ElasticSearchX::Model::Document::Trait::Attribute', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 'ElasticSearchX::Model::Document::Trait::Field::ID', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | has _version => ( | |||||||||||||||||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | property => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | source_only => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | traits => [ | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 'ElasticSearchX::Model::Document::Trait::Attribute', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 'ElasticSearchX::Model::Document::Trait::Field::Version', | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | sub update { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | die "cannot update partially loaded document" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | unless ( $self->meta->all_properties_loaded($self) ); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return $self->put( { $self->_update(@_) } ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | sub _update { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my ( $self, $qs ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $qs ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$qs ||= {}
MC/DC0%0/1
$qs ||= {}
$qs
Truth table0%0/2
A
A= $qs
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return %$qs if ( exists $qs->{version} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $version = $self->_version; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | die "cannot update document without a version" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | unless ($version); | ||||||||||||||||||||||||||||||||||||||||||
| 68 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | version => $version, | |||||||||||||||||||||||||||||||||||||||||
| 70 | %$qs | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | sub create { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return $self->put( { $self->_create(@_) } ); | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | sub _create { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my ( $self, $qs ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $version = $self->_version; | |||||||||||||||||||||||||||||||||||||||||
| 82 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 83 | create => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | %{ $qs || {} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | sub put { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my ( $self, $qs ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | my $method | ||||||||||||||||||||||||||||||||||||||||||
| 92 | = $qs | ||||||||||||||||||||||||||||||||||||||||||
| 93 | && ref $qs eq "HASH" | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | && ( delete $qs->{create} ) ? "create" : "index"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$qs and ref $qs eq "HASH" and delete $qs->{"create"}
$qs and ref $qs eq "HASH"
MC/DC0%0/3
$qs and ref $qs eq "HASH" and delete $qs->{"create"}
$qs
ref $qs eq "HASH"
delete $qs->{"create"}
Truth table0%0/4
A and B and C
A= $qsB= ref $qs eq "HASH"C= delete $qs->{"create"}
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $return = $self->index->model->es->$method( $self->_put($qs) ); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->_clear_loaded_attributes; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $id = $self->meta->get_id_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $id->set_value( $self, $return->{_id} ) if ($id); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $self->meta->get_attribute('_id')->set_value( $self, $return->{_id} ); | |||||||||||||||||||||||||||||||||||||||||
| 100 | $self->meta->get_attribute('_version') | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ->set_value( $self, $return->{_version} ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | sub _put { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my ( $self, $qs ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_put: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $id = $self->meta->get_id_attribute->get_value($self); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $parent = $self->meta->get_parent_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $data = $self->meta->get_data($self); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $qs = { %{ $self->meta->get_query_data($self) }, %{ $qs || {} } }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | index => $self->index->name, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | type => $self->meta->short_name, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | $id ? ( id => $id ) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 115 | body => $data, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | $parent ? ( parent => $parent->get_value($self) ) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 117 | %$qs, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | sub delete { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my ( $self, $qs ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $id = $self->meta->get_id_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 124 | my $return = $self->index->model->es->delete( | ||||||||||||||||||||||||||||||||||||||||||
| 125 | index => $self->index->name, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | type => $self->meta->short_name, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | id => $self->_id, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | %{ $qs || {} }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | sub build_id { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_id: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $id = $self->meta->get_id_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | carp "Need an arrayref of fields for the id, not " . $id->id | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | unless ( ref $id->id eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my @fields = map { $self->meta->get_attribute($_) } @{ $id->id }; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return ElasticSearchX::Model::Util::digest( map { $_->deflate($self) } | |||||||||||||||||||||||||||||||||||||||||
| 140 | @fields ); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | ElasticSearchX::Model::Document::Role | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | version 1.0.3 | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | Moritz Onken | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | This software is Copyright (c) 2018 by Moritz Onken. | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | The (three-clause) BSD License | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||||||||||||||||||||||||