Elastic-Model
view release on metacpan or search on metacpan
lib/Elastic/Model/UID.pm view on Meta::CPAN
has routing => (
#===================================
is => 'ro',
isa => Maybe [Str],
writer => '_routing'
);
#===================================
has from_store => (
#===================================
is => 'ro',
isa => Bool,
writer => '_from_store'
);
#===================================
has 'is_partial' => (
#===================================
is => 'ro',
isa => Bool,
);
#===================================
has cache_key => (
#===================================
is => 'ro',
isa => Str,
lazy => 1,
builder => '_build_cache_key',
clearer => '_clear_cache_key',
);
no Moose;
#===================================
sub new_from_store {
#===================================
my $class = shift;
my %params = %{ shift() };
$class->new(
from_store => 1,
routing => $params{fields}{_routing},
map { $_ => $params{"_$_"} } qw(index type id version)
);
}
#===================================
sub new_partial {
#===================================
my $class = shift;
my %params = %{ shift() };
$class->new(
from_store => 1,
is_partial => 1,
routing => $params{fields}{_routing},
map { $_ => $params{"_$_"} } qw(index type id version)
);
}
#===================================
sub update_from_store {
#===================================
my $self = shift;
my $params = shift;
$self->$_( $params->{$_} ) for qw(_index _id _version);
$self->_from_store(1);
$self->_clear_cache_key;
$self;
}
#===================================
sub update_from_uid {
#===================================
my $self = shift;
my $uid = shift;
$self->_index( $uid->index );
$self->_routing( $uid->routing );
$self->_version( $uid->version );
$self->_from_store(1);
$self->_clear_cache_key;
$self;
}
#===================================
sub clone {
#===================================
my $self = shift;
bless {%$self}, ref $self;
}
#===================================
sub read_params { shift->_params(qw(index type id routing)) }
sub write_params { shift->_params(qw(index type id routing version)) }
#===================================
#===================================
sub _params {
#===================================
my $self = shift;
my %vals;
for (@_) {
my $val = $self->$_ or next;
$vals{$_} = $val;
}
return \%vals;
}
#===================================
sub _build_cache_key {
#===================================
my $self = shift;
return join ";", map { s/;/;;/g; $_ } map { $self->$_ } qw(type id);
}
__PACKAGE__->meta->make_immutable;
1;
=pod
=encoding UTF-8
=head1 NAME
Elastic::Model::UID - The Unique ID of a document in an Elasticsearch cluster
=head1 VERSION
version 0.52
=head1 SYNOPSIS
( run in 0.655 second using v1.01-cache-2.11-cpan-39bf76dae61 )