Model/Document/Mapper.pm

filter: Statementstmt 19.1% 13 / 68 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 16.6% 3 / 18 Podpod 0.0% 0 / 1 totaltotal 13.4% 16 / 119 SCAR 49.3
CC
14
Cov
14%
maptc
56.0
_generic_mapping_sub
42.0
__ANON__
12.0
CRAP 138.8
↑ Summary Model/Document/Attribute/Role/MappingParameters.pm »
1 package Elasticsearch::Model::Document::Mapper;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use List::AllUtils qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 1 my %allowable_types_for_mapping_parameter = (
9 analyzer => ["text"],
10 coerce => ["float", "integer"],
11 eager_global_ordinals => ["keyword","text"],
12 fielddata => ["text"],
13 fields => ["keyword","text"],
14 format => ["date"],
15 ignore_above => ["keyword","text"],
16 normalizer => ["keyword"],
17 position_increment_gap => ["text"],
18 scaling_factor => ["scaled_float"],
19 search_analyzer => ["text"],
20 search_quote_analyzer => ["text"],
21 similarity => ["text"],
22 term_vector => ["text"],
23 );
24  
25 sub _generic_mapping_sub {
26 0 ▶ my ($attribute, $type_constraint, $default_type) = @_;
Subroutine _generic_mapping_sub: not called CC=6 SCAR=37.4
27  
28 0 ▶ my $type = ($attribute->type eq 'object' ? '' : $attribute->type)
Branch: 1 branch
BranchTrueFalseTotal
$attribute->type eq 'object' ? : 0 0 0
Condition0%0/3
($attribute->type eq 'object' ? '' : $attribute->type) || $default_type
l!l&&r!l&&!r
000
MC/DC0%0/2
($attribute->type eq 'object' ? '' : $attribute->type) || $default_type
($attribute->type eq 'object' ? '' : $attribute->type) $default_type
Truth table0%0/3
A || B
A= ($attribute->type eq 'object' ? '' : $attribute->type)B= $default_type
ABresult
1X1
011
000
29 || $default_type;
30 0 my $serialization = $attribute->basic_serialization;
31 0 $serialization->{type} = $type;
32  
33 # Remove illegal mapping parameters, depending on the 'type' of the field.
34 0 for my $mapping_parameter (keys %$serialization) {
35 0 ▶ if (exists $allowable_types_for_mapping_parameter{$mapping_parameter}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $allowable_types_for_mapping_parameter{$mapping_parameter}) 0 0 0
36 0 my $allowable_types = $allowable_types_for_mapping_parameter{$mapping_parameter};
37 0 ▶ delete $serialization->{$mapping_parameter} unless (any { $_ eq $serialization->{type} } @$allowable_types);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_ eq $serialization->{"type"}; } , @$allowable_types) 0 0 0
38 }
39 }
40  
41 0 return %$serialization;
42 }
43  
44 my %mappings = (
45 Any => sub {
46 0 ▶ return _generic_mapping_sub(@_, 'text');
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 },
48 Str => sub {
49 0 ▶ return _generic_mapping_sub(@_, 'text');
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 },
51 Int => sub {
52 0 ▶ return _generic_mapping_sub(@_, 'integer');
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 },
54 Num => sub {
55 0 ▶ return _generic_mapping_sub(@_, 'float');
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 },
57 'Elasticsearch::Model::Types::Location' => sub {
58 0 ▶ return _generic_mapping_sub(@_, 'geo_point');
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 },
60 'Bool' => sub {
61 0 ▶ return _generic_mapping_sub(@_, 'boolean');
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 },
63 'DateTime' => sub {
64 0 ▶ return _generic_mapping_sub(@_, 'date');
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 },
66 'ScalarRef' => sub {
67 0 ▶ my ($attribute, $type_constraint) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 return maptc($attribute, find_type_constraint('Str'));
69 },
70 'ArrayRef' => sub {
71 0 ▶ my ($attribute, $type_constraint) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 return maptc($attribute, find_type_constraint('Str'));
73 },
74 'MooseX::Types::Structured::Dict[]' => sub {
75 0 ▶ my ($attribute, $type_constraint) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
76 0 ▶ my $type = $attribute->type || 'nested';
Condition0%0/2
$attribute->type || 'nested'
l!l
00
MC/DC0%0/1
$attribute->type || 'nested'
$attribute->type
Truth table0%0/2
A
A= $attribute->type
Aresult
11
00
77 0 my %constraints = @{$type_constraint->type_constraints};
78 0 my %properties = ();
79 0 for my $key (keys %constraints) {
80 my %inner_constraint =
81 0 maptc($attribute, $constraints{$key}, "$constraints{$key}");
82 0 $properties{$key} = \%inner_constraint;
83 }
84 0 my %serialization = maptc($attribute, $type_constraint->parent);
85 0 $serialization{type} = $type;
86 0 $serialization{properties} = \%properties;
87 0 return %serialization;
88 },
89 'MooseX::Types::Structured::Optional[]' => sub {
90 0 ▶ my ($attribute, $type_constraint) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 return maptc($attribute, $type_constraint->type_parameter);
92 },
93 'ArrayRef[]' => sub {
94 0 ▶ my ($attribute, $type_constraint) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 my $type_parameter = $type_constraint->type_parameter;
96 0 return maptc($attribute, $type_parameter);
97 },
98 1 );
99  
100 sub maptc {
101 0 ▶ my ($attribute, $type_constraint) = @_;
Subroutine maptc: not called CC=7 SCAR=40.3
Pod undocumented
102 0 my $attr_name = $attribute->name;
103 0 my $original_type_constraint_name = $type_constraint->name;
104  
105 # Get our real constraint out of Maybe before it is reduced to Any
106 0 ▶ if ($type_constraint->name =~ /^Maybe/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_constraint->name =~ /^Maybe/) 0 0 0
107 0 my $type_constraint_name = $original_type_constraint_name;
108  
109 # For Maybe types on a Dict, extract the type_parameter and work with that
110 # For Maybe types on other Moose types, just take the base Moose type.
111 0 ▶ if ($original_type_constraint_name =~
Branch: 1 branch
BranchTrueFalseTotal
if ($original_type_constraint_name =~ /MooseX::Types::Structured::Dict/) { } 0 0 0
112 /MooseX::Types::Structured::Dict/) {
113 0 $type_constraint = $type_constraint->type_parameter;
114 } else {
115 0 ($type_constraint_name = $type_constraint->name) =~
116 s/^Maybe\[(.+?)\]/$1/g;
117 0 $type_constraint = find_type_constraint($type_constraint_name);
118 }
119 }
120  
121 0 ▶ $type_constraint //= find_type_constraint('Str');
Condition0%0/3
$type_constraint //= find_type_constraint("Str")
l!l&&r!l&&!r
000
MC/DC0%0/2
$type_constraint //= find_type_constraint("Str")
$type_constraint find_type_constraint("Str")
Truth table0%0/3
A //= B
A= $type_constraintB= find_type_constraint("Str")
ABresult
1X1
011
000
122  
123 0 (my $name = $type_constraint->name) =~ s/\[.*\]/\[\]/;
124  
125 0 my $sub = $mappings{$name};
126  
127 0 my %ret = ();
128  
129 0 ▶ if (not $sub and $type_constraint->has_parent) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $sub and $type_constraint->has_parent) { } 0 0 0
elsif ($sub) { } 0 0 0
Condition0%0/3
not $sub and $type_constraint->has_parent
!ll&&!rl&&r
000
MC/DC0%0/2
not $sub and $type_constraint->has_parent
not $sub $type_constraint->has_parent
Truth table0%0/3
not(A) and B
A= not $subB= $type_constraint->has_parent
ABresult
0X0
100
111
130  
131 # Ascend type parent hierarchy if required
132 0 %ret = maptc($attribute, $type_constraint->parent);
133  
134 } elsif ($sub) {
135  
136 # Or go ahead and call the subref
137 0 %ret = $sub->($attribute, $type_constraint);
138  
139 }
140  
141 0 return %ret;
142 }
143  
144 1 __PACKAGE__->meta->make_immutable;
145  
146 1 1;
↑ Summary Model/Document/Attribute/Role/MappingParameters.pm »