Search::GIN::Query::Manual - Create manual GIN queries


Search-GIN documentation Contained in the Search-GIN distribution.

Index


Code Index:

NAME

Top

Search::GIN::Query::Manual - Create manual GIN queries

VERSION

Top

version 0.08

SYNOPSIS

Top

    use Search::GIN::Query::Manual;

    my $query = Search::GIN::Query::Manual->new(
        values => {
            name => 'Homer',
        }
    );

DESCRIPTION

Top

Creates a manual GIN query that can be used to search records in a storage.

Unlike the stock GIN queries (Search::GIN::Query::Class, Search::GIN::Query::Attributes), with this object you define your search manually, allowing you to create any search you want.

METHODS/SUBROUTINES

Top

new

Creates a new query.

ATTRIBUTES

Top

values

The keys and values to build the query for.

AUTHOR

Top

Yuval Kogman <nothingmuch@cpan.org>

COPYRIGHT AND LICENSE

Top


Search-GIN documentation Contained in the Search-GIN distribution.

use strict;
use warnings;
package Search::GIN::Query::Manual;
BEGIN {
  $Search::GIN::Query::Manual::VERSION = '0.08';
}
# ABSTRACT: Create manual GIN queries

use Moose;
use namespace::clean -except => 'meta';

with qw(
    Search::GIN::Query
    Search::GIN::Keys::Deep
);

has method => (
    isa => "Str",
    is  => "ro",
    predicate => "has_method",
);

has values => (
    isa => "Any",
    is  => "ro",
    required => 1,
);

has _processed => (
    is => "ro",
    lazy_build => 1,
);

has filter => (
    isa => "CodeRef|Str",
    is  => "ro",
);

sub _build__processed {
    my $self = shift;
    return [ $self->process_keys( $self->values ) ];
}

sub extract_values {
    my $self  = shift;
    my $EMPTY = q{};

    return (
        values => $self->_processed,
        method => $self->has_method ? $self->method : $EMPTY,
    );
}

sub consistent {
    my ( $self, $obj ) = @_;

    if ( my $filter = $self->filter ) {
        return $obj->$filter;
    } else {
        return 1;
    }
}

__PACKAGE__->meta->make_immutable;

1;




__END__