| 1 | use 5.006; # our | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | package Search::GIN::Extract::AttributeIndexes; | ||
| 6 | |||
| 7 | our $VERSION = '2.000000'; | ||
| 8 | |||
| 9 | use Moose qw( has extends ); | ||
| 10 | |||
| 11 | # ABSTRACT: Automatically collect index metadata from MooseX::AttributeIndexes consuming models. | ||
| 12 | |||
| 13 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | ||
| 14 | |||
| 15 | use Scalar::Util qw(blessed reftype); | ||
| 16 | use Safe::Isa qw( $_does ); | ||
| 17 | use Carp; | ||
| 18 | extends 'Search::GIN::Extract::Callback'; | ||
| 19 | use namespace::autoclean; | ||
| 20 | |||
| 21 | has '+extract' => ( default => sub { return \&_extract_object }, ); | ||
| 22 | |||
| 23 | no Moose; | ||
| 24 | __PACKAGE__->meta->make_immutable; | ||
| 25 | |||
| 26 | sub _extract_object { | ||
| 27 | my ( $cache_object, ) = @_; | ||
| 28 | return {} unless $cache_object->$_does('MooseX::AttributeIndexes::Provider'); | ||
| 29 | my $result = $cache_object->attribute_indexes; | ||
| 30 | if ( reftype $result ne 'HASH' ) { | ||
| 31 | Carp::croak( | ||
| 32 | 'the method \'attribute_indexes\' on the class ' . $cache_object->meta->name . ' Does not return an array ref.' ); | ||
| 33 | return {}; | ||
| 34 | } | ||
| 35 | 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.000000 | ||
| 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) 2015 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 |