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