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