| 1 | package Elasticsearch::Model::Document::Role::Metaclass; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | has shortname => ( | |||||||||||
| 7 | is => 'ro', | ||||||||||||
| 8 | builder => '_build_shortname', | ||||||||||||
| 9 | lazy => 1, | ||||||||||||
| 10 | ); | ||||||||||||
| 11 | |||||||||||||
| 12 | sub _build_shortname { | ||||||||||||
| 13 | 3 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_build_shortname: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 3 | ( my $name = $self->name ) =~ s/^.*:://; | |||||||||||
| 15 | 3 | return lc($name); | |||||||||||
| 16 | } | ||||||||||||
| 17 | |||||||||||||
| 18 | has non_attribute_mapping => ( | ||||||||||||
| 19 | is => 'rw', | ||||||||||||
| 20 | isa => 'HashRef', | ||||||||||||
| 21 | 6 | ▶ | default => sub {{}}, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 1 | ); | |||||||||||
| 23 | |||||||||||||
| 24 | 1 | has _all_properties => ( | |||||||||||
| 25 | is => 'ro', | ||||||||||||
| 26 | lazy => 1, | ||||||||||||
| 27 | builder => '_build_all_properties', | ||||||||||||
| 28 | ); | ||||||||||||
| 29 | |||||||||||||
| 30 | sub _build_all_properties { | ||||||||||||
| 31 | return [ | ||||||||||||
| 32 | 3 | ▶ | grep { $_->does('Elasticsearch::Model::Document::Attribute::Role::MappingParameters') } | ||||||||||
|
Subroutine
_build_all_properties: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | shift->get_all_attributes | ||||||||||||
| 34 | ]; | ||||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 1 | has _isa_arrayref => ( | |||||||||||
| 38 | is => 'ro', | ||||||||||||
| 39 | lazy => 1, | ||||||||||||
| 40 | builder => '_build_isa_arrayref', | ||||||||||||
| 41 | ); | ||||||||||||
| 42 | |||||||||||||
| 43 | sub _build_isa_arrayref { | ||||||||||||
| 44 | return { | ||||||||||||
| 45 | map { | ||||||||||||
| 46 | 0 | $_->name => $_->isa_arrayref | |||||||||||
| 47 | 0 | ▶ | } @{shift->_all_properties} | ||||||||||
|
Subroutine
_build_isa_arrayref: not called CC=1 SCAR=6.9
| |||||||||||||
| 48 | }; | ||||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | sub mapping { | ||||||||||||
| 52 | 3 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
mapping: called CC=2 SCAR=8.5
Pod
undocumented
| |||||||||||||
| 53 | 3 | my $props = { map { $_->mapping } $self->get_all_properties }; | |||||||||||
| 54 | return { | ||||||||||||
| 55 | 3 | (keys %{$self->non_attribute_mapping} ? %{$self->non_attribute_mapping} : ()), | |||||||||||
| 56 | properties => $props, | ||||||||||||
| 57 | 3 | ▶ | map { $_->type_mapping } $self->get_all_properties, | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | }; | ||||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | sub add_property { | ||||||||||||
| 62 | 18 | ▶ | my ( $self, $name ) = ( shift, shift ); | ||||||||||
|
Subroutine
add_property: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||
| 63 | 18 | ▶ | Moose->throw_error('Usage: has \'name\' => ( key => value, ... )') | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | if @_ % 2 == 1; | ||||||||||||
| 65 | 18 | my %options = ( definition_context => _caller_info(), @_ ); | |||||||||||
| 66 | 18 | ▶ | $options{traits} //= []; | ||||||||||
|
Condition50%1/2
$options{"traits"} //= []
MC/DC0%0/1
$options{"traits"} //= []
$options{"traits"}
Truth table50%1/2
A
A= $options{"traits"}
| |||||||||||||
| 67 | push( | ||||||||||||
| 68 | 18 | @{ $options{traits} }, | |||||||||||
| 69 | 'Elasticsearch::Model::Document::Attribute::Role::MappingParameters' | ||||||||||||
| 70 | ); | ||||||||||||
| 71 | 18 | ▶ | my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 72 | 18 | $self->add_attribute( $_, %options ) for @$attrs; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | sub _caller_info { | ||||||||||||
| 76 | 18 | ▶ | my $level = @_ ? ( $_[0] + 1 ) : 2; | ||||||||||
|
Subroutine
_caller_info: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||
| 77 | 18 | my %info; | |||||||||||
| 78 | 18 | @info{qw(package file line)} = caller($level); | |||||||||||
| 79 | 18 | return \%info; | |||||||||||
| 80 | } | ||||||||||||
| 81 | |||||||||||||
| 82 | sub get_all_properties { | ||||||||||||
| 83 | 6 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
get_all_properties: called CC=2 SCAR=8.4
Pod
undocumented
| |||||||||||||
| 84 | 6 | ▶ | return @{$self->_all_properties} | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | if ($self->is_immutable); | ||||||||||||
| 86 | 0 | return @{$self->_build_all_properties}; | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 1 | 1; | |||||||||||