lib/Search/GIN/Extract/ClassMap.pm

filter: Statementstmt 97.7% 44 / 45 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.8% 13 / 14 Podpod 100% 1 / 1 totaltotal 96.6% 58 / 60 CC 2 SCAR 1.3
CC
2
Cov
98%
extract_values
2.0
__ANON__
1.1
BEGIN
1.0
CRAP 1.1
« blib/lib/Search/GIN/Extract/ClassMap.pm ↑ Summary blib/lib/Search/GIN/Extract/ClassMap/Role.pm »
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::ClassMap;
6  
7 # ABSTRACT: Delegate Extraction based on class.
8  
9 2 our $VERSION = '1.000002';
10  
11 2 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 2 ▶use Moose 0.90 qw( with has );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Search::GIN::Extract::ClassMap::Types qw( IsaClassMap DoesClassMap LikeClassMap );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use aliased 'Search::GIN::Extract::ClassMap::Isa' => 'CMIsa';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use aliased 'Search::GIN::Extract::ClassMap::Does' => 'CMDoes';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use aliased 'Search::GIN::Extract::ClassMap::Like' => 'CMLike';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 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 1 ▶has 'extract_isa' => ( 'isa', IsaClassMap, 'is', 'rw', 'coerce', 1, default => sub { CMIsa->new() } );
Subroutine __ANON__: called CC=1 SCAR=0.0
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 2 ▶has 'extract_does' => ( 'isa', DoesClassMap, 'is', 'rw', 'coerce', 1, default => sub { CMDoes->new() } );
Subroutine __ANON__: called CC=1 SCAR=0.0
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 0 ▶has 'extract' => ( 'isa', LikeClassMap, 'is', 'rw', 'coerce', 1, default => sub { CMLike->new() } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
109  
110 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 2 __PACKAGE__->meta->make_immutable;
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125 sub extract_values {
126 2 ▶ my ( $self, $extractee ) = @_;
Subroutine extract_values: called CC=2 SCAR=6.9
Pod documented
127 2 my @found;
128 2 for ( $self->extract_isa, $self->extract_does, $self->extract ) {
129 6 push @found, $_->extract_values($extractee);
130 }
131 2 return @found;
132 }
133  
134 2 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.000002
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) 2015 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
« blib/lib/Search/GIN/Extract/ClassMap.pm ↑ Summary blib/lib/Search/GIN/Extract/ClassMap/Role.pm »