| 1 | package MyCPAN::Indexer::Coordinator; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use vars qw($VERSION $logger); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | $VERSION = '1.282'; | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Log::Log4perl; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use YAML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | $logger = Log::Log4perl->get_logger( 'Reporter' ); | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | =encoding utf8 | ||||||||||
| 19 | |||||||||||
| 20 | =head1 NAME | ||||||||||
| 21 | |||||||||||
| 22 | MyCPAN::Indexer::Coordinator - Provide a way for the various components to communicate | ||||||||||
| 23 | |||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||
| 25 | |||||||||||
| 26 | my $componentA = MyCPAN::Indexer::ComponentA->new; | ||||||||||
| 27 | my $componentB = MyCPAN::Indexer::ComponentB->new; | ||||||||||
| 28 | |||||||||||
| 29 | my $coordinator = MyCPAN::Indexer::Coordinator->new; | ||||||||||
| 30 | |||||||||||
| 31 | # each component gets a reference | ||||||||||
| 32 | $componentA->set_coordinator( $coordinator ); | ||||||||||
| 33 | $componentB->set_coordinator( $coordinator ); | ||||||||||
| 34 | |||||||||||
| 35 | # the coordinator knows about all of the components | ||||||||||
| 36 | $coordinator->set_component( 'A', $componentA ); | ||||||||||
| 37 | $coordinator->set_component( 'B', $componentB ); | ||||||||||
| 38 | |||||||||||
| 39 | $componentA->set_note( 'cat', 'Buster' ); | ||||||||||
| 40 | |||||||||||
| 41 | my $cat = $componentB->get_note( 'cat' ); | ||||||||||
| 42 | |||||||||||
| 43 | # Any component can find any other component | ||||||||||
| 44 | $componentB->get_coordinator->get_component( 'A' )->method_in_A; | ||||||||||
| 45 | |||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||
| 47 | |||||||||||
| 48 | The coordinator keeps track of the components in C<MyCPAN::Indexer>. It acts | ||||||||||
| 49 | as a central point where all comunication can flow so everything can talk to | ||||||||||
| 50 | everything with only 2N connections. | ||||||||||
| 51 | |||||||||||
| 52 | It automatically sets up a notes object to act as a scratchpad. Every component | ||||||||||
| 53 | can read from and write to the notes object. | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | =head2 Methods | ||||||||||
| 58 | |||||||||||
| 59 | =over 4 | ||||||||||
| 60 | |||||||||||
| 61 | =item new | ||||||||||
| 62 | |||||||||||
| 63 | Create a new Coordinator object. | ||||||||||
| 64 | |||||||||||
| 65 | =cut | ||||||||||
| 66 | |||||||||||
| 67 | sub new | ||||||||||
| 68 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 69 | 0 | my( $class ) = @_; | |||||||||
| 70 | |||||||||||
| 71 | 0 | require MyCPAN::Indexer::Notes; | |||||||||
| 72 | |||||||||||
| 73 | 0 | my $self = bless { | |||||||||
| 74 | notes => MyCPAN::Indexer::Notes->new, | ||||||||||
| 75 | info => {}, | ||||||||||
| 76 | config => '', | ||||||||||
| 77 | }, $class; | ||||||||||
| 78 | |||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | =item get_component( NAME ) | ||||||||||
| 82 | |||||||||||
| 83 | Retrieve the component named NAME. | ||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||
| 86 | |||||||||||
| 87 | 0 | ▶ | sub get_component { $_[0]->{components}{$_[1]} } | ||||||||
|
Subroutine
get_component: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 88 | |||||||||||
| 89 | =item set_component( NAME, REFERENCE ) | ||||||||||
| 90 | |||||||||||
| 91 | Set the component with name NAME to REFERENCE. So far there are no restrictions | ||||||||||
| 92 | on reference, but it should be a subclass of C<MyCPAN::Indexer::Component> or at | ||||||||||
| 93 | least something that acts like that class. | ||||||||||
| 94 | |||||||||||
| 95 | =cut | ||||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | sub set_component { $_[0]->{components}{$_[1]} = $_[2] } | ||||||||
|
Subroutine
set_component: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 98 | |||||||||||
| 99 | =back | ||||||||||
| 100 | |||||||||||
| 101 | =head2 Dispatch to notes | ||||||||||
| 102 | |||||||||||
| 103 | As a convenience, these methods dispatch to the notes object: | ||||||||||
| 104 | |||||||||||
| 105 | get_note | ||||||||||
| 106 | set_note | ||||||||||
| 107 | get_config | ||||||||||
| 108 | set_config | ||||||||||
| 109 | increment_note | ||||||||||
| 110 | decrement_note | ||||||||||
| 111 | push_onto_note | ||||||||||
| 112 | unshift_onto_note | ||||||||||
| 113 | get_note_list_element | ||||||||||
| 114 | set_note_unless_defined | ||||||||||
| 115 | |||||||||||
| 116 | =cut | ||||||||||
| 117 | |||||||||||
| 118 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.5
| |||||||||||
| 119 | 0 | ▶ | sub get_notes { $_[0]->{notes} } | ||||||||
|
Subroutine
get_notes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 120 | |||||||||||
| 121 | 1 | my @methods_to_dispatch_to_notes = qw( | |||||||||
| 122 | get_note | ||||||||||
| 123 | set_note | ||||||||||
| 124 | increment_note | ||||||||||
| 125 | decrement_note | ||||||||||
| 126 | push_onto_note | ||||||||||
| 127 | unshift_onto_note | ||||||||||
| 128 | get_note_list_element | ||||||||||
| 129 | set_note_unless_defined | ||||||||||
| 130 | ); | ||||||||||
| 131 | |||||||||||
| 132 | |||||||||||
| 133 | 1 | foreach my $method ( @methods_to_dispatch_to_notes ) | |||||||||
| 134 | { | ||||||||||
| 135 | 1 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 136 | 8 | ▶ | *{$method} = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||
| 137 | 0 | my $self = shift; | |||||||||
| 138 | 0 | $self->get_notes->$method( @_ ); | |||||||||
| 139 | } | ||||||||||
| 140 | 8 | } | |||||||||
| 141 | |||||||||||
| 142 | } | ||||||||||
| 143 | |||||||||||
| 144 | =head2 Organic methods | ||||||||||
| 145 | |||||||||||
| 146 | These methods are defined in this class and work to interact with some | ||||||||||
| 147 | of the things the coordinator is tracking. | ||||||||||
| 148 | |||||||||||
| 149 | =over 4 | ||||||||||
| 150 | |||||||||||
| 151 | =item get_config | ||||||||||
| 152 | |||||||||||
| 153 | =item set_config( CONFIG ) | ||||||||||
| 154 | |||||||||||
| 155 | Get or set the configuration objects. | ||||||||||
| 156 | |||||||||||
| 157 | =cut | ||||||||||
| 158 | |||||||||||
| 159 | 0 | ▶ | sub get_config { $_[0]->{config} } | ||||||||
|
Subroutine
get_config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 160 | 0 | ▶ | sub set_config { $_[0]->{config} = $_[1] } | ||||||||
|
Subroutine
set_config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 161 | |||||||||||
| 162 | =item get_info | ||||||||||
| 163 | |||||||||||
| 164 | =item set_info( INFO_OBJ ) | ||||||||||
| 165 | |||||||||||
| 166 | Get or set the info object. This is the thing that records the data | ||||||||||
| 167 | collected during the index. | ||||||||||
| 168 | |||||||||||
| 169 | =cut | ||||||||||
| 170 | |||||||||||
| 171 | 0 | ▶ | sub get_info { $_[0]->{info} } | ||||||||
|
Subroutine
get_info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 172 | 0 | ▶ | sub set_info { $_[0]->{info} = $_[1] } | ||||||||
|
Subroutine
set_info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 173 | |||||||||||
| 174 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.9
| |||||||||||
| 175 | 1 | my @components = ( | |||||||||
| 176 | [qw( queue get_queue )], | ||||||||||
| 177 | [qw( dispatcher get_dispatcher)], | ||||||||||
| 178 | [qw( worker get_task )], | ||||||||||
| 179 | [qw( indexer run )], | ||||||||||
| 180 | [qw( reporter get_reporter )], | ||||||||||
| 181 | [qw( interface do_interface )], | ||||||||||
| 182 | [qw( application activate )], | ||||||||||
| 183 | [qw( collator get_collator )], | ||||||||||
| 184 | ); | ||||||||||
| 185 | |||||||||||
| 186 | 1 | foreach my $tuple ( @components ) | |||||||||
| 187 | { | ||||||||||
| 188 | 8 | my( $component, $required_method ) = @$tuple; | |||||||||
| 189 | |||||||||||
| 190 | 1 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 191 | 0 | ▶ | *{"get_${component}"} = sub { $_[0]->get_component( $component ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||||||||||
| 192 | 8 | ▶ | *{"set_${component}"} = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.6
| |||||||||||
| 193 | die "$component must implement $required_method" | ||||||||||
| 194 | 0 | ▶ | unless eval { $_[1]->can( $required_method ) }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 195 | 0 | $_[0]->set_component( $component, $_[1] ); | |||||||||
| 196 | 8 | }; | |||||||||
| 197 | } | ||||||||||
| 198 | } | ||||||||||
| 199 | |||||||||||
| 200 | =back | ||||||||||
| 201 | |||||||||||
| 202 | =head1 TO DO | ||||||||||
| 203 | |||||||||||
| 204 | =head1 SOURCE AVAILABILITY | ||||||||||
| 205 | |||||||||||
| 206 | This code is in Github: | ||||||||||
| 207 | |||||||||||
| 208 | git://github.com/briandfoy/mycpan-indexer.git | ||||||||||
| 209 | |||||||||||
| 210 | =head1 AUTHOR | ||||||||||
| 211 | |||||||||||
| 212 | brian d foy, C<< <bdfoy@cpan.org> >> | ||||||||||
| 213 | |||||||||||
| 214 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 215 | |||||||||||
| 216 | Copyright © 2008-2018, brian d foy <bdfoy@cpan.org>. All rights reserved. | ||||||||||
| 217 | |||||||||||
| 218 | You may redistribute this under the terms of the Artistic License 2.0. | ||||||||||
| 219 | |||||||||||
| 220 | =cut | ||||||||||
| 221 | |||||||||||
| 222 | 1 | 1; | |||||||||