File Coverage

blib/lib/Search/GIN/Query/Manual.pm
Criterion Covered Total %
statement 8 10 80.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 12 14 85.7


line stmt bran cond sub pod time code
1 1     1   2049 use strict;
  1         2  
  1         32  
2 1     1   7 use warnings;
  1         1  
  1         44  
3             package Search::GIN::Query::Manual;
4             BEGIN {
5 1     1   32 $Search::GIN::Query::Manual::AUTHORITY = 'cpan:NUFFIN';
6             }
7             # ABSTRACT: Create manual GIN queries
8             $Search::GIN::Query::Manual::VERSION = '0.09';
9 1     1   537 use Moose;
  0            
  0            
10             use namespace::clean -except => 'meta';
11              
12             with qw(
13             Search::GIN::Query
14             Search::GIN::Keys::Deep
15             );
16              
17             has method => (
18             isa => "Str",
19             is => "ro",
20             predicate => "has_method",
21             );
22              
23             has values => (
24             isa => "Any",
25             is => "ro",
26             required => 1,
27             );
28              
29             has _processed => (
30             is => "ro",
31             lazy_build => 1,
32             );
33              
34             has filter => (
35             isa => "CodeRef|Str",
36             is => "ro",
37             );
38              
39             sub _build__processed {
40             my $self = shift;
41             return [ $self->process_keys( $self->values ) ];
42             }
43              
44             sub extract_values {
45             my $self = shift;
46             my $EMPTY = q{};
47              
48             return (
49             values => $self->_processed,
50             method => $self->has_method ? $self->method : $EMPTY,
51             );
52             }
53              
54             sub consistent {
55             my ( $self, $index, $obj ) = @_;
56              
57             if ( my $filter = $self->filter ) {
58             return $obj->$filter;
59             } else {
60             return 1;
61             }
62             }
63              
64             __PACKAGE__->meta->make_immutable;
65              
66             1;
67              
68             __END__
69              
70             =pod
71              
72             =encoding UTF-8
73              
74             =head1 NAME
75              
76             Search::GIN::Query::Manual - Create manual GIN queries
77              
78             =head1 VERSION
79              
80             version 0.09
81              
82             =head1 SYNOPSIS
83              
84             use Search::GIN::Query::Manual;
85              
86             my $query = Search::GIN::Query::Manual->new(
87             values => {
88             name => 'Homer',
89             }
90             );
91              
92             =head1 DESCRIPTION
93              
94             Creates a manual GIN query that can be used to search records in a storage.
95              
96             Unlike the stock GIN queries (L<Search::GIN::Query::Class>,
97             L<Search::GIN::Query::Attributes>), with this object you define your search
98             manually, allowing you to create any search you want.
99              
100             =head1 METHODS/SUBROUTINES
101              
102             =head2 new
103              
104             Creates a new query.
105              
106             =head1 ATTRIBUTES
107              
108             =head2 values
109              
110             The keys and values to build the query for.
111              
112             =head1 AUTHOR
113              
114             יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is copyright (c) 2008 by יובל קוג'מן (Yuval Kogman), Infinity Interactive.
119              
120             This is free software; you can redistribute it and/or modify it under
121             the same terms as the Perl 5 programming language system itself.
122              
123             =cut