| 1 | package App::ElasticSearch::Utilities::QueryString::Plugin; | ||||||||||||||
| 2 | # ABSTRACT: Moo::Role for implementing QueryString Plugins | ||||||||||||||
| 3 | |||||||||||||||
| 4 | 9 | ▶ | use v5.16; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 9 | our $VERSION = '9.1'; # VERSION | |||||||||||||
| 8 | |||||||||||||||
| 9 | 9 | ▶ | use Hash::Merge::Simple qw(clone_merge); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 9 | ▶ | use Moo::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 9 | ▶ | use Ref::Util qw(is_arrayref is_hashref); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 9 | ▶ | use Types::Standard qw( HashRef Str Int ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | |||||||||||||||
| 15 | # Attributes | ||||||||||||||
| 16 | 9 | has name => ( | |||||||||||||
| 17 | is => 'lazy', | ||||||||||||||
| 18 | isa => Str, | ||||||||||||||
| 19 | ); | ||||||||||||||
| 20 | 7 | ▶ | sub _build_name { | ||||||||||||
|
Subroutine
_build_name: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | 7 | my $self = shift; | |||||||||||||
| 22 | 7 | my $class = ref $self; | |||||||||||||
| 23 | 7 | return (split /::/, $class)[-1]; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | |||||||||||||||
| 26 | |||||||||||||||
| 27 | 9 | has priority => ( | |||||||||||||
| 28 | is => 'lazy', | ||||||||||||||
| 29 | isa => Int, | ||||||||||||||
| 30 | ); | ||||||||||||||
| 31 | 1 | ▶ | sub _build_priority { 50; } | ||||||||||||
|
Subroutine
_build_priority: called CC=1 SCAR=0.0
| |||||||||||||||
| 32 | |||||||||||||||
| 33 | |||||||||||||||
| 34 | has fields_meta => ( | ||||||||||||||
| 35 | is => 'rw', | ||||||||||||||
| 36 | isa => HashRef, | ||||||||||||||
| 37 | 0 | ▶ | default => sub { {} }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 38 | 9 | ); | |||||||||||||
| 39 | |||||||||||||||
| 40 | |||||||||||||||
| 41 | 9 | requires qw(handle_token); | |||||||||||||
| 42 | |||||||||||||||
| 43 | 70 | ▶ | around 'handle_token' => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||
| 44 | 70 | my $orig = shift; | |||||||||||||
| 45 | 70 | my $self = shift; | |||||||||||||
| 46 | 70 | my $refs = $orig->($self,@_); | |||||||||||||
| 47 | 70 | ▶ | if( defined $refs ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | 18 | ▶ | if( is_arrayref($refs) ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 49 | 8 | foreach my $doc (@{ $refs }) { | |||||||||||||
| 50 | 8 | $doc->{_by} = $self->name; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | } | ||||||||||||||
| 53 | elsif( is_hashref($refs) ) { | ||||||||||||||
| 54 | 10 | $refs->{_by} = $self->name; | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | 18 | return $refs; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | else { | ||||||||||||||
| 59 | 52 | return; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | 9 | }; | |||||||||||||
| 62 | |||||||||||||||
| 63 | |||||||||||||||
| 64 | # Handle Build Args | ||||||||||||||
| 65 | |||||||||||||||
| 66 | |||||||||||||||
| 67 | 7 | ▶ | sub BUILDARGS { | ||||||||||||
|
Subroutine
BUILDARGS: called CC=6 SCAR=19.6
Pod
undocumented
| |||||||||||||||
| 68 | 7 | my($class,%in) = @_; | |||||||||||||
| 69 | |||||||||||||||
| 70 | 7 | my @search = map { $_ => lc $_ } ($class,(split /::/, $class)[-1]); | |||||||||||||
| 71 | 7 | ▶ | my $options = exists $in{options} ? delete $in{options} : {}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | |||||||||||||||
| 73 | 7 | my @options = (); | |||||||||||||
| 74 | 7 | foreach my $s (@search) { | |||||||||||||
| 75 | 28 | ▶ | if( exists $options->{$s} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 0 | push @options, $options->{$s}; | |||||||||||||
| 77 | 0 | last; | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | } | ||||||||||||||
| 80 | 7 | ▶ | push @options, \%in if keys %in; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 81 | |||||||||||||||
| 82 | 7 | ▶ | return scalar(@options) ? clone_merge(@options) : {}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 9 | 1; | |||||||||||||
| 86 | |||||||||||||||
| 87 | __END__ | ||||||||||||||