| 1 | 7 | ▶ | use 5.006; # our | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Search::GIN::Extract::ClassMap::Types; | ||||||||||
| 6 | |||||||||||
| 7 | # ABSTRACT: Types for Search::GIN::Extract::ClassMap, mostly for coercing. | ||||||||||
| 8 | |||||||||||
| 9 | 7 | our $VERSION = '1.000002'; | |||||||||
| 10 | |||||||||||
| 11 | 7 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||
| 12 | |||||||||||
| 13 | 7 | ▶ | use MooseX::Types::Moose qw( :all ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 7 | use MooseX::Types -declare => [ | |||||||||
| 15 | qw[ | ||||||||||
| 16 | IsaClassMap | ||||||||||
| 17 | DoesClassMap | ||||||||||
| 18 | LikeClassMap | ||||||||||
| 19 | Extractor | ||||||||||
| 20 | CoercedClassMap | ||||||||||
| 21 | ], | ||||||||||
| 22 | 7 | ▶ | ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | ## no critic (Subroutines::ProhibitCallsToUndeclaredSubs) | ||||||||||
| 37 | 7 | class_type IsaClassMap, { class => 'Search::GIN::Extract::ClassMap::Isa' }; | |||||||||
| 38 | |||||||||||
| 39 | coerce IsaClassMap, from HashRef, via { | ||||||||||
| 40 | 3 | ▶ | require Search::GIN::Extract::ClassMap::Isa; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 3 | 'Search::GIN::Extract::ClassMap::Isa'->new( classmap => $_ ); | |||||||||
| 42 | 7 | }; | |||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | 7 | class_type DoesClassMap, { class => 'Search::GIN::Extract::ClassMap::Does' }; | |||||||||
| 57 | |||||||||||
| 58 | coerce DoesClassMap, from HashRef, via { | ||||||||||
| 59 | 2 | ▶ | require Search::GIN::Extract::ClassMap::Does; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 2 | 'Search::GIN::Extract::ClassMap::Does'->new( classmap => $_ ); | |||||||||
| 61 | 7 | }; | |||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | |||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | 7 | class_type LikeClassMap, { class => 'Search::GIN::Extract::ClassMap::Like' }; | |||||||||
| 76 | |||||||||||
| 77 | coerce LikeClassMap, from HashRef, via { | ||||||||||
| 78 | 4 | ▶ | require Search::GIN::Extract::ClassMap::Like; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 79 | 4 | 'Search::GIN::Extract::ClassMap::Like'->new( classmap => $_ ); | |||||||||
| 80 | 7 | }; | |||||||||
| 81 | |||||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | |||||||||||
| 88 | |||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | |||||||||||
| 94 | |||||||||||
| 95 | |||||||||||
| 96 | |||||||||||
| 97 | |||||||||||
| 98 | |||||||||||
| 99 | |||||||||||
| 100 | |||||||||||
| 101 | |||||||||||
| 102 | subtype Extractor, as Object, where { | ||||||||||
| 103 | 12 | ▶ | $_->does('Search::GIN::Extract') | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 104 | or $_->isa('Search::GIN::Extract'); | ||||||||||
| 105 | 7 | }; | |||||||||
| 106 | |||||||||||
| 107 | coerce Extractor, from ArrayRef [Str], via { | ||||||||||
| 108 | 5 | ▶ | require Search::GIN::Extract::Attributes; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 109 | 5 | Search::GIN::Extract::Attributes->new( attributes => $_ ); | |||||||||
| 110 | |||||||||||
| 111 | 7 | }; | |||||||||
| 112 | coerce Extractor, from CodeRef, via { | ||||||||||
| 113 | 1 | ▶ | require Search::GIN::Extract::Callback; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 114 | 1 | Search::GIN::Extract::Callback->new( extract => $_ ); | |||||||||
| 115 | 7 | }; | |||||||||
| 116 | |||||||||||
| 117 | |||||||||||
| 118 | |||||||||||
| 119 | |||||||||||
| 120 | |||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | |||||||||||
| 124 | |||||||||||
| 125 | |||||||||||
| 126 | |||||||||||
| 127 | |||||||||||
| 128 | |||||||||||
| 129 | |||||||||||
| 130 | |||||||||||
| 131 | |||||||||||
| 132 | |||||||||||
| 133 | |||||||||||
| 134 | subtype CoercedClassMap, as HashRef, where { | ||||||||||
| 135 | 24 | ▶ | for my $v ( values %{$_} ) { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 136 | 12 | ▶ | return unless is_Extractor($v); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | } | ||||||||||
| 138 | 18 | return 1; | |||||||||
| 139 | }, message { | ||||||||||
| 140 | 0 | ▶ | for my $k ( keys %{$_} ) { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 141 | 0 | ▶ | next if is_Extractor( $_->{$k} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | 0 | return "Key $k in the hash expected Search::GIN::Extract implementation"; | |||||||||
| 143 | } | ||||||||||
| 144 | 7 | }; | |||||||||
| 145 | |||||||||||
| 146 | coerce CoercedClassMap, from HashRef, via { | ||||||||||
| 147 | 6 | ▶ | my $newhashref = {}; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 148 | 6 | my $old = $_; | |||||||||
| 149 | 6 | for my $key ( keys %{$old} ) { | |||||||||
| 150 | 6 | $newhashref->{$key} = to_Extractor( $old->{$key} ); | |||||||||
| 151 | } | ||||||||||
| 152 | 6 | return $newhashref; | |||||||||
| 153 | 7 | }; | |||||||||
| 154 | |||||||||||
| 155 | 7 | 1; | |||||||||
| 156 | |||||||||||
| 157 | __END__ | ||||||||||
| 158 | |||||||||||
| 159 | =pod | ||||||||||
| 160 | |||||||||||
| 161 | =encoding UTF-8 | ||||||||||
| 162 | |||||||||||
| 163 | =head1 NAME | ||||||||||
| 164 | |||||||||||
| 165 | Search::GIN::Extract::ClassMap::Types - Types for Search::GIN::Extract::ClassMap, mostly for coercing. | ||||||||||
| 166 | |||||||||||
| 167 | =head1 VERSION | ||||||||||
| 168 | |||||||||||
| 169 | version 1.000002 | ||||||||||
| 170 | |||||||||||
| 171 | =head1 TYPES | ||||||||||
| 172 | |||||||||||
| 173 | =head2 C<IsaClassMap> | ||||||||||
| 174 | |||||||||||
| 175 | =over 4 | ||||||||||
| 176 | |||||||||||
| 177 | =item C<class_type> : L<< C<::ClassMap::Isa>|Search::GIN::Extract::ClassMap::Isa >> | ||||||||||
| 178 | |||||||||||
| 179 | =item C<coerces_from>: C<HashRef> | ||||||||||
| 180 | |||||||||||
| 181 | =back | ||||||||||
| 182 | |||||||||||
| 183 | =head2 C<DoesClassMap> | ||||||||||
| 184 | |||||||||||
| 185 | =over 4 | ||||||||||
| 186 | |||||||||||
| 187 | =item C<class_type>: L<< C<::ClassMap::Does>|Search::GIN::Extract::ClassMap::Does >> | ||||||||||
| 188 | |||||||||||
| 189 | =item coerces from: C<HashRef> | ||||||||||
| 190 | |||||||||||
| 191 | =back | ||||||||||
| 192 | |||||||||||
| 193 | =head2 C<LikeClassMap> | ||||||||||
| 194 | |||||||||||
| 195 | =over 4 | ||||||||||
| 196 | |||||||||||
| 197 | =item C<class_type>: L<< C<::ClassMap::Like>|Search::GIN::Extract::ClassMap::Like >> | ||||||||||
| 198 | |||||||||||
| 199 | =item coerces from: C<HashRef> | ||||||||||
| 200 | |||||||||||
| 201 | =back | ||||||||||
| 202 | |||||||||||
| 203 | =head2 C<Extractor> | ||||||||||
| 204 | |||||||||||
| 205 | Mostly here to identify things that derive from L<< C<Search::GIN::Extract>|Search::GIN::Extract >> | ||||||||||
| 206 | |||||||||||
| 207 | =over 4 | ||||||||||
| 208 | |||||||||||
| 209 | =item C<subtype>: C<Object> | ||||||||||
| 210 | |||||||||||
| 211 | =item coerces from: C<ArrayRef[ Str ]> | ||||||||||
| 212 | |||||||||||
| 213 | Coerces into a L<< C<::Extract::Attributes>|Search::GIN::Extract::Attributes >> instance. | ||||||||||
| 214 | |||||||||||
| 215 | =item coerces from: C<CodeRef> | ||||||||||
| 216 | |||||||||||
| 217 | Coerces into a L<< C<::Extract::Callback>|Search::GIN::Extract::Callback >> instance. | ||||||||||
| 218 | |||||||||||
| 219 | =back | ||||||||||
| 220 | |||||||||||
| 221 | =head2 C<CoercedClassMap> | ||||||||||
| 222 | |||||||||||
| 223 | This is here to implement a ( somewhat hackish ) semi-deep recursive coercion. | ||||||||||
| 224 | |||||||||||
| 225 | Ensures all keys are of type L</Extractor> in order to be a valid C<HashRef>, | ||||||||||
| 226 | and coerces to L</Extractor>'s where possible. | ||||||||||
| 227 | |||||||||||
| 228 | =over 4 | ||||||||||
| 229 | |||||||||||
| 230 | =item C<subtype>: C<HashRef[ Extractor ]> | ||||||||||
| 231 | |||||||||||
| 232 | =item coerces from: C<HashRef[ coerce Extractor ]> | ||||||||||
| 233 | |||||||||||
| 234 | =back | ||||||||||
| 235 | |||||||||||
| 236 | =head1 AUTHOR | ||||||||||
| 237 | |||||||||||
| 238 | Kent Fredric <kentnl@cpan.org> | ||||||||||
| 239 | |||||||||||
| 240 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 241 | |||||||||||
| 242 | This software is copyright (c) 2015 by Kent Fredric <kentfredric@gmail.com>. | ||||||||||
| 243 | |||||||||||
| 244 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 245 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 246 | |||||||||||
| 247 | =cut | ||||||||||