Model/Document/Types.pm

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