File Coverage

blib/lib/Search/GIN/Query/Manual.pm
Criterion Covered Total %
statement 20 21 95.2
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 29 34 85.2


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