| 1 | package MyCPAN::Indexer::Component; | ||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use Carp qw( croak ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Scalar::Util qw( weaken ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | $VERSION = '1.282'; | |||||||||
| 11 | |||||||||||
| 12 | =encoding utf8 | ||||||||||
| 13 | |||||||||||
| 14 | =head1 NAME | ||||||||||
| 15 | |||||||||||
| 16 | MyCPAN::Indexer::Component - base class for MyCPAN components | ||||||||||
| 17 | |||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||
| 19 | |||||||||||
| 20 | package MyCPAN::Indexer::NewComponent; | ||||||||||
| 21 | |||||||||||
| 22 | use base qw(MyCPAN::Indexer::Component); | ||||||||||
| 23 | |||||||||||
| 24 | sub component_type { $_[0]->reporter_type } | ||||||||||
| 25 | |||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||
| 27 | |||||||||||
| 28 | This module implements features common to all C<MyCPAN::Indexer> | ||||||||||
| 29 | components. Each component is able to communicate with a coordinator | ||||||||||
| 30 | object to find out the results and notes left by other components. | ||||||||||
| 31 | Most of that delegation infrastructure is hidden since each component | ||||||||||
| 32 | can call methods on its own instances that this module dispatches | ||||||||||
| 33 | appropriately. | ||||||||||
| 34 | |||||||||||
| 35 | =cut | ||||||||||
| 36 | |||||||||||
| 37 | =head2 Methods | ||||||||||
| 38 | |||||||||||
| 39 | =over 4 | ||||||||||
| 40 | |||||||||||
| 41 | =item new( [COORDINATOR] ) | ||||||||||
| 42 | |||||||||||
| 43 | Create a new component object. This is mostly to have a place to | ||||||||||
| 44 | store a reference to the coordinator object. See C<get_coordinator>. | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub component_type { croak "Component classes must implement component_type" } | ||||||||
|
Subroutine
component_type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 49 | |||||||||||
| 50 | sub new | ||||||||||
| 51 | 2 | ▶ | { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||
| 52 | 2 | my( $class, $coordinator ) = @_; | |||||||||
| 53 | |||||||||||
| 54 | 2 | my $self = bless {}, $class; | |||||||||
| 55 | |||||||||||
| 56 | 2 | ▶ | if( defined $coordinator ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | { | ||||||||||
| 58 | 0 | $self->set_coordinator( $coordinator ); | |||||||||
| 59 | 0 | $coordinator->set_note( $self->component_type, $self ); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 2 | $self; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | =item get_coordinator | ||||||||||
| 66 | |||||||||||
| 67 | Get the coordinator object. This is the object that coordinates all of the | ||||||||||
| 68 | components. Each component communicates with the coordinator and other | ||||||||||
| 69 | components can see it. | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||
| 72 | |||||||||||
| 73 | 0 | ▶ | sub get_coordinator { $_[0]->{_coordinator} } | ||||||||
|
Subroutine
get_coordinator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 74 | |||||||||||
| 75 | =item set_coordinator( $coordinator ) | ||||||||||
| 76 | |||||||||||
| 77 | Set the coordinator object. C<new> already does this for you if you pass it a | ||||||||||
| 78 | coordinator object. Each component expects the cooridnator object to respond | ||||||||||
| 79 | to these methods: | ||||||||||
| 80 | |||||||||||
| 81 | get_info | ||||||||||
| 82 | set_info | ||||||||||
| 83 | get_note | ||||||||||
| 84 | set_note | ||||||||||
| 85 | get_config | ||||||||||
| 86 | set_config | ||||||||||
| 87 | increment_note | ||||||||||
| 88 | decrement_note | ||||||||||
| 89 | push_onto_note | ||||||||||
| 90 | unshift_onto_note | ||||||||||
| 91 | get_note_list_element | ||||||||||
| 92 | set_note_unless_defined | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | |||||||||||
| 96 | 3 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
| |||||||||||
| 97 | |||||||||||
| 98 | 3 | my @methods_to_dispatch_to_coordinator = qw( | |||||||||
| 99 | get_info | ||||||||||
| 100 | set_info | ||||||||||
| 101 | get_note | ||||||||||
| 102 | set_note | ||||||||||
| 103 | get_config | ||||||||||
| 104 | set_config | ||||||||||
| 105 | get_component | ||||||||||
| 106 | increment_note | ||||||||||
| 107 | decrement_note | ||||||||||
| 108 | push_onto_note | ||||||||||
| 109 | unshift_onto_note | ||||||||||
| 110 | get_note_list_element | ||||||||||
| 111 | set_note_unless_defined | ||||||||||
| 112 | ); | ||||||||||
| 113 | |||||||||||
| 114 | 3 | foreach my $method ( @methods_to_dispatch_to_coordinator ) | |||||||||
| 115 | { | ||||||||||
| 116 | 3 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 117 | 39 | ▶ | *{$method} = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||
| 118 | 0 | my $self = shift; | |||||||||
| 119 | 0 | $self->get_coordinator->$method( @_ ); | |||||||||
| 120 | } | ||||||||||
| 121 | 39 | } | |||||||||
| 122 | |||||||||||
| 123 | sub set_coordinator | ||||||||||
| 124 | 0 | ▶ | { | ||||||||
|
Subroutine
set_coordinator: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 125 | 0 | my( $self, $coordinator ) = @_; | |||||||||
| 126 | |||||||||||
| 127 | 0 | my @missing = grep { ! $coordinator->can( $_ ) } | |||||||||
| 128 | @methods_to_dispatch_to_coordinator; | ||||||||||
| 129 | |||||||||||
| 130 | 0 | ▶ | croak "Coordinator object is missing these methods: @missing" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | if @missing; | ||||||||||
| 132 | |||||||||||
| 133 | 0 | $self->{_coordinator} = $coordinator; | |||||||||
| 134 | |||||||||||
| 135 | 0 | weaken( $self->{_coordinator} ); | |||||||||
| 136 | |||||||||||
| 137 | 0 | return $self->{_coordinator}; | |||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | =item null_type | ||||||||||
| 143 | |||||||||||
| 144 | =item collator_type | ||||||||||
| 145 | |||||||||||
| 146 | =item dispatcher_type | ||||||||||
| 147 | |||||||||||
| 148 | =item indexer_type | ||||||||||
| 149 | |||||||||||
| 150 | =item interface_type | ||||||||||
| 151 | |||||||||||
| 152 | =item queue_type | ||||||||||
| 153 | |||||||||||
| 154 | =item reporter_type | ||||||||||
| 155 | |||||||||||
| 156 | =item worker_type | ||||||||||
| 157 | |||||||||||
| 158 | Returns the magic number that identifies the component type. You shouldn't | ||||||||||
| 159 | ever have to look at the particular number. Some components might have | ||||||||||
| 160 | several types. | ||||||||||
| 161 | |||||||||||
| 162 | =cut | ||||||||||
| 163 | |||||||||||
| 164 | 0 | ▶ | sub null_type { 0 } | ||||||||
|
Subroutine
null_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 165 | 0 | ▶ | sub collator_type { 0b00000001 } | ||||||||
|
Subroutine
collator_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 166 | 0 | ▶ | sub dispatcher_type { 0b00000010 } | ||||||||
|
Subroutine
dispatcher_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 167 | 0 | ▶ | sub indexer_type { 0b00000100 } | ||||||||
|
Subroutine
indexer_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 168 | 0 | ▶ | sub interface_type { 0b00001000 } | ||||||||
|
Subroutine
interface_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 169 | 0 | ▶ | sub queue_type { 0b00010000 } | ||||||||
|
Subroutine
queue_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 170 | 0 | ▶ | sub reporter_type { 0b00100000 } | ||||||||
|
Subroutine
reporter_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 171 | 0 | ▶ | sub worker_type { 0b01000000 } | ||||||||
|
Subroutine
worker_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 172 | |||||||||||
| 173 | =item combine_types( TYPES ) | ||||||||||
| 174 | |||||||||||
| 175 | For components that implement several roles, create a composite type: | ||||||||||
| 176 | |||||||||||
| 177 | my $custom_type = $self->combine_types( | ||||||||||
| 178 | map { $self->$_() } qw( queue_type worker_type ); | ||||||||||
| 179 | } | ||||||||||
| 180 | |||||||||||
| 181 | If you want to test that value, use the C<is_type> methods. | ||||||||||
| 182 | |||||||||||
| 183 | =cut | ||||||||||
| 184 | |||||||||||
| 185 | sub combine_types | ||||||||||
| 186 | 0 | ▶ | { | ||||||||
|
Subroutine
combine_types: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 187 | 0 | my( $self, @types ) = @_; | |||||||||
| 188 | |||||||||||
| 189 | 0 | my $combined_type = 0; | |||||||||
| 190 | |||||||||||
| 191 | 0 | foreach my $type ( @types ) | |||||||||
| 192 | { | ||||||||||
| 193 | 0 | $combined_type |= $type; | |||||||||
| 194 | } | ||||||||||
| 195 | |||||||||||
| 196 | 0 | return $combined_type; | |||||||||
| 197 | } | ||||||||||
| 198 | |||||||||||
| 199 | =item is_type( CONCRETE, TEST ) | ||||||||||
| 200 | |||||||||||
| 201 | Tests a CONCRETE type (the one a component claims to be) with the TYPE | ||||||||||
| 202 | that you want to check. This is the general test. | ||||||||||
| 203 | |||||||||||
| 204 | =cut | ||||||||||
| 205 | |||||||||||
| 206 | 0 | ▶ | sub is_type { $_[1] & $_[2] } | ||||||||
|
Subroutine
is_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 207 | |||||||||||
| 208 | =item is_null_type | ||||||||||
| 209 | |||||||||||
| 210 | =item is_collator_type | ||||||||||
| 211 | |||||||||||
| 212 | =item is_dispatcher_type | ||||||||||
| 213 | |||||||||||
| 214 | =item is_indexer_type | ||||||||||
| 215 | |||||||||||
| 216 | =item is_interface_type | ||||||||||
| 217 | |||||||||||
| 218 | =item is_queue_type | ||||||||||
| 219 | |||||||||||
| 220 | =item is_reporter_type | ||||||||||
| 221 | |||||||||||
| 222 | =item is_worker_type | ||||||||||
| 223 | |||||||||||
| 224 | These are curried versions of C<is_type>. They should be a bit easier to use. | ||||||||||
| 225 | |||||||||||
| 226 | =cut | ||||||||||
| 227 | |||||||||||
| 228 | 0 | ▶ | sub is_null_type { $_[1] == 0 } | ||||||||
|
Subroutine
is_null_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 229 | 0 | ▶ | sub is_collator_type { $_[0]->is_type( $_[1], $_[0]->collator_type ) } | ||||||||
|
Subroutine
is_collator_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 230 | 0 | ▶ | sub is_dispatcher_type { $_[0]->is_type( $_[1], $_[0]->dispatcher_type ) } | ||||||||
|
Subroutine
is_dispatcher_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 231 | 0 | ▶ | sub is_indexer_type { $_[0]->is_type( $_[1], $_[0]->indexer_type ) } | ||||||||
|
Subroutine
is_indexer_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 232 | 0 | ▶ | sub is_interface_type { $_[0]->is_type( $_[1], $_[0]->interface_type ) } | ||||||||
|
Subroutine
is_interface_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 233 | 0 | ▶ | sub is_queue_type { $_[0]->is_type( $_[1], $_[0]->queue_type ) } | ||||||||
|
Subroutine
is_queue_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 234 | 0 | ▶ | sub is_reporter_type { $_[0]->is_type( $_[1], $_[0]->reporter_type ) } | ||||||||
|
Subroutine
is_reporter_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 235 | 0 | ▶ | sub is_worker_type { $_[0]->is_type( $_[1], $_[0]->worker_type ) } | ||||||||
|
Subroutine
is_worker_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 236 | |||||||||||
| 237 | =back | ||||||||||
| 238 | |||||||||||
| 239 | =head1 SOURCE AVAILABILITY | ||||||||||
| 240 | |||||||||||
| 241 | This code is in Github: | ||||||||||
| 242 | |||||||||||
| 243 | git://github.com/briandfoy/mycpan-indexer.git | ||||||||||
| 244 | |||||||||||
| 245 | =head1 AUTHOR | ||||||||||
| 246 | |||||||||||
| 247 | brian d foy, C<< <bdfoy@cpan.org> >> | ||||||||||
| 248 | |||||||||||
| 249 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 250 | |||||||||||
| 251 | Copyright © 2008-2018, brian d foy <bdfoy@cpan.org>. All rights reserved. | ||||||||||
| 252 | |||||||||||
| 253 | You may redistribute this under the terms of the Artistic License 2.0. | ||||||||||
| 254 | |||||||||||
| 255 | =cut | ||||||||||
| 256 | |||||||||||
| 257 | 3 | 1; | |||||||||