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