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