File Coverage

blib/lib/Search/GIN/Extract/AttributeIndexes.pm
Criterion Covered Total %
statement 31 33 93.9
branch 2 4 50.0
condition n/a
subroutine 10 10 100.0
pod n/a
total 43 47 91.4


line stmt bran cond sub pod time code
1 2     2   481376 use 5.006; # our
  2         6  
2 2     2   12 use strict;
  2         2  
  2         53  
3 2     2   19 use warnings;
  2         3  
  2         149  
4              
5             package Search::GIN::Extract::AttributeIndexes;
6              
7             our $VERSION = '2.000001';
8              
9 2     2   524 use Moose qw( has extends );
  2         339694  
  2         13  
10              
11             # ABSTRACT: Automatically collect index metadata from MooseX::AttributeIndexes consuming models.
12              
13             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
14              
15 2     2   8896 use Scalar::Util qw(blessed reftype);
  2         4  
  2         152  
16 2     2   1112 use Safe::Isa qw( $_does );
  2         799  
  2         251  
17 2     2   11 use Carp;
  2         2  
  2         122  
18             extends 'Search::GIN::Extract::Callback';
19 2     2   382 use namespace::autoclean;
  2         5899  
  2         14  
20              
21             has '+extract' => ( default => sub { return \&_extract_object }, );
22              
23 2     2   206 no Moose;
  2         4  
  2         14  
24             __PACKAGE__->meta->make_immutable;
25              
26             sub _extract_object {
27 3     3   10 my ( $cache_object, ) = @_;
28 3 50       22 return {} unless $cache_object->$_does('MooseX::AttributeIndexes::Provider');
29 3         620 my $result = $cache_object->attribute_indexes;
30 3 50       5338 if ( reftype $result ne 'HASH' ) {
31 0         0 Carp::croak(
32             'the method \'attribute_indexes\' on the class ' . $cache_object->meta->name . ' Does not return an array ref.' );
33 0         0 return {};
34             }
35 3         12 return $result;
36             }
37              
38             1;
39              
40             __END__
41              
42             =pod
43              
44             =encoding UTF-8
45              
46             =head1 NAME
47              
48             Search::GIN::Extract::AttributeIndexes - Automatically collect index metadata from MooseX::AttributeIndexes consuming models.
49              
50             =head1 VERSION
51              
52             version 2.000001
53              
54             =head1 SYNOPSIS
55              
56             =head2 On your models
57              
58             use MooseX::Declare;
59              
60             class Model::Item {
61             use MooseX::Types::Moose qw(:all ):
62             use MooseX::AttributeIndexes;
63              
64             has 'attr' => (
65             isa => Str,
66             is => 'rw',
67             indexed => 1
68             );
69             has 'attr_bar' => (
70             isa => Str,
71             is => 'rw',
72             primary_index => 1
73             );
74             }
75              
76             =head2 In KiokuX::Model extensions
77              
78             use MooseX::Declare;
79              
80             class Foo extends KiokuX::Model {
81             use Search::GIN::Extract::AttributeIndexes;
82              
83             around _build_connect_args ( Any @args ) {
84              
85             my $args = $self->$orig( @args );
86             push @{ $args }, extract => Search::GIN::Extract::AttributeIndexes->new();
87             return $args;
88              
89             }
90             }
91              
92             =head2 In Instantiations of KiokuDB
93              
94             my $dir = KiouDB->new(
95             backend => KiokuDB::Backend::BDB::GIN->new(
96             extract => Search::GIN::Extract::AttributeIndexes->new()
97             )
98             );
99              
100             =head1 DESCRIPTION
101              
102             This module is an extension for the C<Search::GIN> search and index framework
103             which allows one to operate objects of any class consuming
104             C<MooseX::AttributeIndexes>, and extracting values from those objects for use
105             in indexing.
106              
107             This allows people to define how an object should be indexed on the class
108             definition itself by adding properties to attributes.
109              
110             =head1 AUTHOR
111              
112             Kent Fredric <kentnl@cpan.org>
113              
114             =head1 COPYRIGHT AND LICENSE
115              
116             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
117              
118             This is free software; you can redistribute it and/or modify it under
119             the same terms as the Perl 5 programming language system itself.
120              
121             =cut