File Coverage

blib/lib/KiokuDB/Backend/Role/Query/Simple.pm
Criterion Covered Total %
statement 12 12 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 18 20 90.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package KiokuDB::Backend::Role::Query::Simple;
4 21     21   10107 use Moose::Role;
  21         35  
  21         124  
5              
6 21     21   84536 use namespace::clean -except => 'meta';
  21         237  
  21         150  
7              
8             requires "simple_search";
9              
10             sub simple_search_filter {
11 66     66 0 116 my ( $self, $stream, $proto ) = @_;
12 66         292 return $stream;
13             }
14              
15             # FIXME unify with Attribute, and put this in the default simple_search_filter
16             # implementation
17             # that way *really* lazy backends can just alias simple_search to scan and
18             # still be feature complete even if they are retardedly slow
19              
20             sub compare_naive {
21 201     201 0 267 my ( $self, $got, $exp ) = @_;
22              
23 201         455 foreach my $key ( keys %$exp ) {
24 201 100       575 return unless overload::StrVal($got->{$key}) eq overload::StrVal($exp->{$key});
25             }
26              
27 101         1917 return 1;
28             }
29              
30             __PACKAGE__
31              
32             __END__
33              
34             =pod
35              
36             =head1 NAME
37              
38             KiokuDB::Backend::Role::Query::Simple - Simple query api
39              
40             =head1 SYNOPSIS
41              
42             with qw(KiokuDB::Backend::Role::Query::Simple);
43              
44             sub simple_search {
45             my ( $self, $proto ) = @_;
46              
47             # return all candidate entries in the root set matching fields in $proto
48             return Data::Stream::Bulk::Foo->new(...);
49             }
50              
51             =head1 DESCRIPTION
52              
53             This role requires a C<simple_search> method to be implemented.
54              
55             The method accepts one argument, the hash of the proto to search for.
56              
57             This is still loosely defined, but the basic functionality is based on
58             attribute matching:
59              
60             $kiokudb->search({ name => "Mia" });
61              
62             will search for objects whose C<name> attribute contains the string C<Mia>.
63              
64             More complex operations will be defined in the future.
65              
66             =cut
67              
68