blib/lib/ElasticSearchX/Model/Document/Types.pm

filter: Statementstmt 82.4% 94 / 114 Branchbran 14.2% 2 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 61.3% 27 / 44 Podpod n/a totaltotal 71.5% 123 / 172 CC 8 SCAR 8.2
CC
8
Cov
75%
__ANON__
6.0
__ANON__
6.0
__ANON__
6.0
CRAP 2.3
« blib/lib/ElasticSearchX/Model/Document/Trait/Attribute.pm ↑ Summary blib/lib/ElasticSearchX/Model/Document/Trait/Field/ID.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::Types;
11 24 $ElasticSearchX::Model::Document::Types::VERSION = '1.0.3';
12 24 ▶use List::MoreUtils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 24 ▶use DateTime::Format::Epoch::Unix;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 24 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 24 ▶use MooseX::Attribute::Deflator;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 24 ▶use MooseX::Attribute::Deflator::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 24 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 24 ▶use JSON::MaybeXS qw( decode_json encode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 24 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 24 ▶use MooseX::Types::ElasticSearch qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 24 use MooseX::Types -declare => [
23 qw(
24 Type
25 Types
26 TimestampField
27 TTLField
28 )
29 24 ▶];
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 24 use Sub::Exporter -setup => {
32 exports => [
33 qw(
34 Location
35 QueryType
36 ES
37 Type
38 Types
39 TimestampField
40 TTLField
41 )
42 ]
43 24 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 24 ▶use MooseX::Types::Moose qw/Int Str Bool ArrayRef HashRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 24 ▶use MooseX::Types::Structured qw(Dict Tuple Optional slurpy);
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 24 subtype TimestampField,
49 as Dict [
50 enabled => Bool,
51 path => Optional [Str],
52 index => Optional [Str],
53 slurpy HashRef,
54 ];
55 coerce TimestampField, from Int, via {
56 0 ▶ { enabled => 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 24 };
58 coerce TimestampField, from Str, via {
59 0 ▶ { enabled => 1, path => $_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 24 };
61 coerce TimestampField, from HashRef, via {
62 0 ▶ { enabled => 1, %$_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 24 };
64  
65 24 subtype TTLField,
66 as Dict [
67 enabled => Bool,
68 default => Optional [Str],
69 store => Optional [Bool],
70 index => Optional [Str],
71 slurpy HashRef,
72 ];
73 coerce TTLField, from Int, via {
74 0 ▶ { enabled => 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 24 };
76 coerce TTLField, from Str, via {
77 0 ▶ { enabled => 1, default => $_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 24 };
79 coerce TTLField, from HashRef, via {
80 0 ▶ { enabled => 1, %$_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 24 };
82  
83 24 class_type 'DateTime';
84 coerce 'DateTime', from Int, via {
85 1 ▶ DateTime->from_epoch( epoch => $_ / 1000 );
Subroutine __ANON__: called CC=1 SCAR=0.0
86 24 };
87 coerce 'DateTime', from Str, via {
88 2 ▶ DateTime::Format::ISO8601->parse_datetime($_);
Subroutine __ANON__: called CC=1 SCAR=0.0
89 24 };
90  
91 subtype Types, as HashRef ['Object'], where {
92 0 ▶ !grep { $_->isa('Moose::Meta::Class') } keys %$_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
93 }, message {
94 0 ▶ "Types must be either an ArrayRef of class names or a HashRef of name/class name pairs";
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 24 };
96  
97 coerce Types, from HashRef ['Str'], via {
98 1 ▶ my $hash = $_;
Subroutine __ANON__: called CC=1 SCAR=0.0
99 return {
100 1 map { $_ => Class::MOP::Class->initialize( $hash->{$_} ) }
101 keys %$hash
102 };
103 24 };
104  
105 coerce Types, from ArrayRef ['Str'], via {
106 1 ▶ my $array = $_;
Subroutine __ANON__: called CC=1 SCAR=0.0
107 return {
108 map {
109 1 my $meta = Class::MOP::Class->initialize($_);
110 2 $meta->short_name => $meta
111 } @$array
112 };
113 24 };
114  
115 24 my $REGISTRY = Moose::Util::TypeConstraints->get_type_constraint_registry;
116  
117 $REGISTRY->add_type_constraint(
118 Moose::Meta::TypeConstraint::Parameterizable->new(
119 name => Type,
120 package_defined_in => __PACKAGE__,
121 parent => find_type_constraint('Object'),
122 constraint_generator => sub {
123 sub {
124 0 ▶ blessed $_
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) and $_->can("_does_elasticsearchx_model_document_role") 0 0 0
125 && $_->can('_does_elasticsearchx_model_document_role');
126 }
127 2 ▶ },
Subroutine __ANON__: called CC=1 SCAR=0.0
128 )
129 24 );
130  
131 24 Moose::Util::TypeConstraints::add_parameterizable_type(
132 $REGISTRY->get_type_constraint(Type) );
133  
134 24 ▶use MooseX::Attribute::Deflator;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 my @stat
136 24 = qw(dev ino mode nlink uid gid rdev size atime mtime ctime blksize blocks);
137 0 ▶deflate 'File::stat', via { return { List::MoreUtils::mesh( @stat, @$_ ) } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
138 inline_as {
139 0 ▶ join( "\n",
Subroutine __ANON__: not called CC=1 SCAR=6.9
140 'my @stat = qw(dev ino mode nlink uid gid',
141 'rdev size atime mtime ctime blksize blocks);',
142 'List::MoreUtils::mesh( @stat, @$value )',
143 );
144 24 };
145 deflate [ 'ArrayRef', 'HashRef' ],
146 0 ▶ via { shift->dynamic ? $_ : encode_json($_) }, inline_as {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
(shift())->dynamic ? : 0 0 0
147 2 ▶ return '$value' if ( $_[0]->dynamic );
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->dynamic 0 2 2
148 2 return 'JSON::encode_json($value)';
149 24 };
150 inflate [ 'ArrayRef', 'HashRef' ],
151 0 ▶ via { shift->dynamic ? $_ : decode_json($_) }, inline_as {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
(shift())->dynamic ? : 0 0 0
152 2 ▶ return '$value' if ( $_[0]->dynamic );
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->dynamic 0 2 2
153 2 return 'JSON::decode_json($value)';
154 24 };
155  
156 0 ▶deflate 'ArrayRef', via {$_}, inline_as {'$value'};
Subroutine __ANON__: not called CC=1 SCAR=0.4
157 3 ▶inflate 'ArrayRef', via {$_}, inline_as {'$value'};
Subroutine __ANON__: called CC=1 SCAR=0.4
158  
159 1 ▶deflate 'DateTime', via { $_->iso8601 }, inline_as {'$value->iso8601'};
Subroutine __ANON__: called CC=1 SCAR=0.4
160 inflate 'DateTime', via {
161 0 ▶ $_ =~ /^\d+$/
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /^\d+$/ ? : 0 0 0
162 ? DateTime->from_epoch( epoch => $_ / 1000 )
163 : DateTime::Format::ISO8601->parse_datetime($_);
164 }, inline_as {
165 1 ▶ q(
Subroutine __ANON__: called CC=1 SCAR=0.0
166 $value =~ /^\d+$/
167 ? DateTime->from_epoch(epoch => $value/1000)
168 : DateTime::Format::ISO8601->parse_datetime($value)
169 )
170 24 };
171 0 ▶deflate Location, via { [ $_->[0] + 0, $_->[1] + 0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
172 1 ▶ inline_as {'[ $value->[0] + 0, $value->[1] + 0 ]'};
Subroutine __ANON__: called CC=1 SCAR=0.0
173 0 ▶deflate Type . '[]', via { ref $_ eq 'HASH' ? $_ : $_->meta->get_data($_) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 0 0 0
174 inline_as {
175 2 ▶ 'ref $value eq "HASH" ? $value : $value->meta->get_data($value)';
Subroutine __ANON__: called CC=1 SCAR=0.0
176 24 };
177  
178 24 ▶no MooseX::Attribute::Deflator;
Subroutine BEGIN: called CC=1 SCAR=0.0
179  
180 24 1;
181  
182 __END__
183  
184 =pod
185  
186 =encoding UTF-8
187  
188 =head1 NAME
189  
190 ElasticSearchX::Model::Document::Types
191  
192 =head1 VERSION
193  
194 version 1.0.3
195  
196 =head1 AUTHOR
197  
198 Moritz Onken
199  
200 =head1 COPYRIGHT AND LICENSE
201  
202 This software is Copyright (c) 2018 by Moritz Onken.
203  
204 This is free software, licensed under:
205  
206 The (three-clause) BSD License
207  
208 =cut
« blib/lib/ElasticSearchX/Model/Document/Trait/Attribute.pm ↑ Summary blib/lib/ElasticSearchX/Model/Document/Trait/Field/ID.pm »