File Coverage

blib/lib/Search/GIN/Extract/ClassMap.pm
Criterion Covered Total %
statement 34 34 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod 1 1 100.0
total 46 46 100.0


line stmt bran cond sub pod time code
1 2     2   19742 use 5.006; # our
  2         6  
2 2     2   11 use strict;
  2         3  
  2         50  
3 2     2   8 use warnings;
  2         3  
  2         155  
4              
5             package Search::GIN::Extract::ClassMap;
6              
7             # ABSTRACT: Delegate Extraction based on class.
8              
9             our $VERSION = '1.000003';
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 2     2   1074 use Moose 0.90 qw( with has );
  2         761298  
  2         17  
14 2     2   13470 use Search::GIN::Extract::ClassMap::Types qw( IsaClassMap DoesClassMap LikeClassMap );
  2         7  
  2         11  
15 2     2   4595 use aliased 'Search::GIN::Extract::ClassMap::Isa' => 'CMIsa';
  2         784  
  2         12  
16 2     2   213 use aliased 'Search::GIN::Extract::ClassMap::Does' => 'CMDoes';
  2         2  
  2         12  
17 2     2   200 use aliased 'Search::GIN::Extract::ClassMap::Like' => 'CMLike';
  2         3  
  2         13  
18 2     2   233 use namespace::autoclean;
  2         4  
  2         61  
19              
20             with qw( Search::GIN::Extract );
21              
22              
23              
24              
25              
26              
27              
28              
29              
30              
31              
32              
33              
34              
35              
36              
37              
38              
39              
40              
41              
42              
43              
44              
45              
46              
47              
48              
49             has 'extract_isa' => ( 'isa', IsaClassMap, 'is', 'rw', 'coerce', 1, default => sub { CMIsa->new() } );
50              
51              
52              
53              
54              
55              
56              
57              
58              
59              
60              
61              
62              
63              
64              
65              
66              
67              
68              
69              
70              
71              
72              
73              
74              
75              
76              
77             has 'extract_does' => ( 'isa', DoesClassMap, 'is', 'rw', 'coerce', 1, default => sub { CMDoes->new() } );
78              
79              
80              
81              
82              
83              
84              
85              
86              
87              
88              
89              
90              
91              
92              
93              
94              
95              
96              
97              
98              
99              
100              
101              
102              
103              
104              
105              
106              
107              
108             has 'extract' => ( 'isa', LikeClassMap, 'is', 'rw', 'coerce', 1, default => sub { CMLike->new() } );
109              
110 2     2   540 no Moose;
  2         4  
  2         14  
111             __PACKAGE__->meta->make_immutable;
112              
113              
114              
115              
116              
117              
118              
119              
120              
121              
122              
123              
124              
125             sub extract_values {
126 2     2 1 1496 my ( $self, $extractee ) = @_;
127 2         4 my @found;
128 2         107 for ( $self->extract_isa, $self->extract_does, $self->extract ) {
129 6         412 push @found, $_->extract_values($extractee);
130             }
131 2         588 return @found;
132             }
133              
134             1;
135              
136             __END__
137              
138             =pod
139              
140             =encoding UTF-8
141              
142             =head1 NAME
143              
144             Search::GIN::Extract::ClassMap - Delegate Extraction based on class.
145              
146             =head1 VERSION
147              
148             version 1.000003
149              
150             =head1 SYNOPSIS
151              
152             my $extractor = Search::GIN::Extract::ClassMap->new(
153             extract_isa => {
154             'Foo' => [qw( bar baz quux )],
155             'Bar' => Search::GIN::Extract::AttributeIndex->new(),
156             'Baz' => sub { shift; my $object = shift; { a => $object->a() } },
157             },
158             extract_does => {
159              
160             },
161             extract => {
162             /* either ISA or DOES */
163             },
164             );
165              
166             In reality, the form is more like this:
167              
168             my $extractor = Search::GIN::Extract::ClassMap->new(
169             extract_isa => {
170             'Foo' => Search::GIN::Extract::*,
171             'Bar' => Search::GIN::Extract::*,
172             'Baz' => Search::GIN::Extract::*,
173             },
174             extract_does => {
175              
176             },
177             extract => {
178             /* either ISA or DOES */
179             },
180             );
181              
182             With the minor exception of the 2 exception cases, passing
183             an C<ArrayRef>, or a C<CodeRef>, which internally are type-cast to
184             L<< C<Search::GIN::Extract::Attributes>|Search::GIN::Extract::Attributes >>
185             and L<< C<Search::GIN::Extract::Callback>|Search::GIN::Extract::Callback >>
186             automatically.
187              
188             =head1 WARNING
189              
190             This is an early release, C<API> is prone to change without much warning, but best attempts will be made to avoid the need.
191              
192             =head1 DESCRIPTION
193              
194             This module is an extension for the L<< C<Search::GIN>|Search::GIN >> framework
195             providing a novel way to dictate which attribute extraction techniques will be
196             used for which object by having rules that map against the objects inheritance
197             or the objects composed roles.
198              
199             This essentially permits you to register adapters for various object types to
200             special-case their extraction.
201              
202             For example, if you had a source tree that used classes under your control
203             using C<MooseX::AttributeIndexes>, you could easily default those classes to
204             extract using C<Search::GIN::Extract::AttributeIndexes>. And if any objects of
205             those classes had C<DateTime> properties, you could define a handler for
206             extracting C<DateTime> meta-data for indexing specifically.
207              
208             =head1 METHODS
209              
210             =head2 C<extract_values>
211              
212             my ( @values ) = $object->extract_values( $extractee );
213              
214             B<for:> L<< C<Search::GIN::Extract>|Search::GIN::Extract >>
215              
216             Iterates the contents of the C<< extract($|_\w+$) >> rules, and asks them to
217             extract their respective information, and returns the resulting results as a
218             list.
219              
220             =head1 ATTRIBUTES
221              
222             =head2 C<extract_isa>
223              
224             my $object = Search::GIN::Extract::ClassMap->new(
225             extract_isa => $isa_thing
226             );
227             # or
228             $object->extract_isa( $isa_thing )
229              
230             Applied on all objects where $object->isa( $classname );
231              
232             =head3 C<$isa_thing>
233              
234             =over 4
235              
236             =item C<< HashRef[ L<Extractor|Search::GIN::Extract::ClassMap::Types/Extractor> ] >>
237              
238             =item L<< C<CoercedClassMap>|Search::GIN::Extract::ClassMap::Types/CoercedClassMap >>
239              
240             =item L<< C<::ClassMap::Isa>|Search::GIN::Extract::ClassMap::Isa >>
241              
242             C<HashRef>'s are automatically type-cast.
243              
244             =back
245              
246             =head2 C<extract_does>
247              
248             my $object = Search::GIN::Extract::ClassMap->new(
249             extract_does => $does_thing
250             );
251             # or
252             $object->extract_does( $does_thing );
253              
254             Applied on all objects where $object->does( $classname );
255              
256             =head3 C<$does_thing>
257              
258             =over 4
259              
260             =item C<< HashRef[ L<Extractor|Search::GIN::Extract::ClassMap::Types/Extractor> ] >>
261              
262             =item L<< C<CoercedClassMap>|Search::GIN::Extract::ClassMap::Types/CoercedClassMap >>
263              
264             =item L<< C<::ClassMap::Does>|Search::GIN::Extract::ClassMap::Does >>
265              
266             C<HashRef>'s are automatically type-cast.
267              
268             =back
269              
270             =head2 C<extract>
271              
272             my $object = Search::GIN::Extract::ClassMap->new(
273             extract => $like_thing
274             );
275             # or
276             $object->extract( $like_thing );
277              
278             Applied on all objects where $object->does( $classname ) OR $object->isa( $classname );
279              
280             this doesn't make complete sense, but its handy for lazy people.
281              
282             =head3 C<$like_thing>
283              
284             =over 4
285              
286             =item C<< HashRef[ L<Extractor|Search::GIN::Extract::ClassMap::Types/Extractor> ] >>
287              
288             =item L<< C<CoercedClassMap>|Search::GIN::Extract::ClassMap::Types/CoercedClassMap >>
289              
290             =item L<< C<::ClassMap::Like>|Search::GIN::Extract::ClassMap::Like >>
291              
292             C<HashRef>'s are automatically type-cast.
293              
294             =back
295              
296             =head1 AUTHOR
297              
298             Kent Fredric <kentnl@cpan.org>
299              
300             =head1 COPYRIGHT AND LICENSE
301              
302             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
303              
304             This is free software; you can redistribute it and/or modify it under
305             the same terms as the Perl 5 programming language system itself.
306              
307             =cut