| 1 | # | ||||||||||||||||||||||||||||||||||||||
| 2 | # This file is part of MooseX-Types-ElasticSearch | ||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2014 by Moritz Onken. | ||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||
| 8 | # The (three-clause) BSD License | ||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||
| 10 | package MooseX::Types::ElasticSearch; | ||||||||||||||||||||||||||||||||||||||
| 11 | 1 | $MooseX::Types::ElasticSearch::VERSION = '0.0.4'; | |||||||||||||||||||||||||||||||||||||
| 12 | # ABSTRACT: Useful types for ElasticSearch | ||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use DateTime::Format::Epoch::Unix; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use DateTime::Format::ISO8601; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Search::Elasticsearch; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use MooseX::Types -declare => [ | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | qw( | ||||||||||||||||||||||||||||||||||||||
| 20 | Location | ||||||||||||||||||||||||||||||||||||||
| 21 | QueryType | ||||||||||||||||||||||||||||||||||||||
| 22 | SearchType | ||||||||||||||||||||||||||||||||||||||
| 23 | ES | ||||||||||||||||||||||||||||||||||||||
| 24 | ESDateTime | ||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ) ]; | |||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use MooseX::Types::Moose qw/Int Str ArrayRef HashRef Object/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | coerce ArrayRef, from Str, via { [$_] }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 1 | subtype ES, as Object; | |||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | coerce ES, from Str, via { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $server = $_; | |||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $server = "127.0.0.1$server" if ( $server =~ /^:/ ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 35 | return | ||||||||||||||||||||||||||||||||||||||
| 36 | 0 | Search::Elasticsearch->new( nodes => $server, | |||||||||||||||||||||||||||||||||||||
| 37 | cxn => "HTTPTiny", | ||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||
| 39 | 1 | }; | |||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | coerce ES, from HashRef, via { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return Search::Elasticsearch->new(%$_); | |||||||||||||||||||||||||||||||||||||
| 43 | 1 | }; | |||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | coerce ES, from ArrayRef, via { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my @servers = @$_; | |||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | @servers = map { /^:/ ? "127.0.0.1$_" : $_ } @servers; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 48 | return | ||||||||||||||||||||||||||||||||||||||
| 49 | 0 | Search::Elasticsearch->new( nodes => \@servers, | |||||||||||||||||||||||||||||||||||||
| 50 | cxn => "HTTPTiny", | ||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||
| 52 | 1 | }; | |||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||
| 54 | 1 | enum QueryType, [qw(query_and_fetch query_then_fetch dfs_query_and_fetch dfs_query_then_fetch scan count)]; | |||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | 1 | subtype SearchType, as QueryType; | |||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | 1 | class_type ESDateTime; | |||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | coerce ESDateTime, from Str, via { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( $_ =~ /^\d+$/ ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 61 | 0 | DateTime::Format::Epoch::Unix->parse_datetime($_); | |||||||||||||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||||||||||||
| 63 | 0 | DateTime::Format::ISO8601->parse_datetime($_); | |||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | 1 | }; | |||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | subtype Location, | ||||||||||||||||||||||||||||||||||||||
| 68 | as ArrayRef, | ||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | where { @$_ == 2 }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | message { "Location is an arrayref of longitude and latitude" }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||
| 72 | coerce Location, from HashRef, | ||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | via { [ $_->{lon} || $_->{longitude}, $_->{lat} || $_->{latitude} ] }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=22.0
Condition0%0/6
$_->{'lon'} || $_->{'longitude'}
$_->{'lat'} || $_->{'latitude'}
MC/DC0%0/2
$_->{'lon'} || $_->{'longitude'}
$_->{'lon'}
$_->{'longitude'}
MC/DC0%0/2
$_->{'lat'} || $_->{'latitude'}
$_->{'lat'}
$_->{'latitude'}
Truth table0%0/3
A || B
A= $_->{'lon'}B= $_->{'longitude'}
Truth table0%0/3
A || B
A= $_->{'lat'}B= $_->{'latitude'}
| |||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | coerce Location, from Str, via { [ reverse split(/,/) ] }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||||||||||||