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