File Coverage

blib/lib/Search/GIN/Core.pm
Criterion Covered Total %
statement 30 33 90.9
branch 2 2 100.0
condition n/a
subroutine 8 9 88.8
pod 0 3 0.0
total 40 47 85.1


line stmt bran cond sub pod time code
1 4     4   3139 use strict;
  4         7  
  4         168  
2 4     4   21 use warnings;
  4         7  
  4         248  
3             package Search::GIN::Core;
4             # ABSTRACT: Core of Search::GIN
5             our $VERSION = '0.10';
6 4     4   23 use Moose::Role;
  4         8  
  4         43  
7 4     4   22071 use Data::Stream::Bulk::Util qw(bulk unique);
  4         432435  
  4         28  
8 4     4   928 use namespace::autoclean;
  4         8  
  4         37  
9              
10             with qw(
11             Search::GIN::Driver
12             Search::GIN::Extract
13             );
14              
15             requires qw(
16             objects_to_ids
17             ids_to_objects
18             );
19              
20             has distinct => (
21             isa => "Bool",
22             is => "rw",
23             default => 0, # FIXME what should the default be?
24             );
25              
26             sub query {
27 14     14 0 10482 my ( $self, $query, @args ) = @_;
28              
29 14         496 my %args = (
30             distinct => $self->distinct,
31             @args,
32             );
33              
34 14         74 my @spec = $query->extract_values($self);
35              
36 14         365 my $ids = $self->fetch_entries(@spec);
37              
38 14 100       847 $ids = unique($ids) if $args{distinct};
39              
40 14     13   1235 return $ids->filter(sub { [ grep { $query->consistent($self, $_) } $self->ids_to_objects(@$_) ] });
  13         1144  
  26         429  
41             }
42              
43             sub remove {
44 0     0 0 0 my ( $self, @items ) = @_;
45              
46 0         0 my @ids = $self->objects_to_ids(@items);
47              
48 0         0 $self->remove_ids(@ids);
49             }
50              
51             sub insert {
52 4     4 0 1482 my ( $self, @items ) = @_;
53              
54 4         25 my @ids = $self->objects_to_ids(@items);
55              
56 4         8 my @entries;
57              
58 4         11 foreach my $item ( @items ) {
59 16         48 my @keys = $self->extract_values( $item, gin => $self );
60 16         105 my $id = shift @ids;
61              
62 16         48 $self->insert_entry( $id, @keys );
63             }
64             }
65              
66             1;
67              
68             __END__
69              
70             =pod
71              
72             =encoding UTF-8
73              
74             =head1 NAME
75              
76             Search::GIN::Core - Core of Search::GIN
77              
78             =head1 VERSION
79              
80             version 0.10
81              
82             =head1 AUTHOR
83              
84             יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
85              
86             =head1 COPYRIGHT AND LICENSE
87              
88             This software is copyright (c) 2008 by יובל קוג'מן (Yuval Kogman), Infinity Interactive.
89              
90             This is free software; you can redistribute it and/or modify it under
91             the same terms as the Perl 5 programming language system itself.
92              
93             =cut