ElasticSearchX-Model
view release on metacpan or search on metacpan
lib/ElasticSearchX/Model/Document/Trait/Attribute.pm view on Meta::CPAN
#
# This file is part of ElasticSearchX-Model
#
# This software is Copyright (c) 2019 by Moritz Onken.
#
# This is free software, licensed under:
#
# The (three-clause) BSD License
#
package ElasticSearchX::Model::Document::Trait::Attribute;
$ElasticSearchX::Model::Document::Trait::Attribute::VERSION = '2.0.1';
# ABSTRACT: Trait that extends the meta class of a document class
use Moose::Role;
use ElasticSearchX::Model::Document::Mapping;
with 'MooseX::Attribute::LazyInflator::Meta::Role::Attribute';
use ElasticSearchX::Model::Document::Types qw(:all);
use MooseX::Types::Moose qw(ArrayRef);
has index => ( is => 'ro' );
has boost => ( is => 'ro', isa => 'Num' );
has store => ( is => 'ro', isa => 'Str', default => 'yes' );
has type => ( is => 'ro', isa => 'Str', default => 'string' );
has parent => ( is => 'ro', isa => 'Bool', default => 0 );
has dynamic => ( is => 'ro', isa => 'Bool', default => 0 );
has analyzer =>
( is => 'ro', isa => ArrayRef, coerce => 1, default => sub { [] } );
has not_analyzed => ( is => 'ro', isa => 'Bool', default => 1 );
has term_vector => ( is => 'ro', isa => 'Str' );
has include_in_all => ( is => 'ro', isa => 'Bool', default => 1 );
has source_only => ( is => 'ro', isa => 'Bool', default => 0 );
has include_in_root => ( is => 'ro', isa => 'Bool' );
has include_in_parent => ( is => 'ro', isa => 'Bool' );
has property => ( is => 'ro', isa => 'Bool', default => 1 );
has query_property => ( is => 'ro', isa => 'Bool', default => 0 );
has field_name =>
( is => 'ro', isa => 'Str', lazy => 1, default => sub { shift->name } );
has isa_arrayref => (
is => 'ro',
lazy => 1,
isa => 'Bool',
builder => '_build_isa_arrayref'
);
sub _build_isa_arrayref {
my $self = shift;
my $tc = $self->type_constraint;
return 0 unless $tc;
return $tc->is_a_type_of("ArrayRef");
}
sub build_property {
my $self = shift;
return {
ElasticSearchX::Model::Document::Mapping::maptc(
$self, $self->type_constraint
)
};
}
before _process_options => sub {
my ( $self, $name, $options ) = @_;
%$options = ( builder => 'build_id', lazy => 1, %$options )
if ( $options->{id} && ref $options->{id} eq 'ARRAY' );
$options->{traits} ||= [];
push(
@{ $options->{traits} },
'MooseX::Attribute::LazyInflator::Meta::Role::Attribute'
) if ( $options->{property} || !exists $options->{property} );
};
after _process_options => sub {
my ( $class, $name, $options ) = @_;
if ( $options->{required}
&& !$options->{builder}
&& !defined $options->{default} )
{
$options->{lazy} = 1;
$options->{required} = 1;
$options->{default} = sub {
confess "Attribute $name is required";
};
}
};
sub mapping {
( run in 1.799 second using v1.01-cache-2.11-cpan-39bf76dae61 )