1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
use 5.008001;
use strict;
use warnings;
package CPAN::Common::Index;
# ABSTRACT: Common library for searching CPAN modules, authors and distributions
our $VERSION = '0.010';
use Carp ();
use Class::Tiny;
#--------------------------------------------------------------------------#
# Document abstract methods
#--------------------------------------------------------------------------#
#pod =method search_packages (ABSTRACT)
#pod
#pod $result = $index->search_packages( { package => "Moose" });
#pod @result = $index->search_packages( \%advanced_query );
#pod
#pod Searches the index for a package such as listed in the CPAN
#pod F<02packages.details.txt> file. The query must be provided as a hash
#pod reference. Valid keys are
#pod
#pod =for :list
#pod * package -- a string, regular expression or code reference
#pod * version -- a version number or code reference
#pod * dist -- a string, regular expression or code reference
#pod
#pod If the query term is a string or version number, the query will be for an exact
#pod match. If a code reference, the code will be called with the value of the
#pod field for each potential match. It should return true if it matches.
#pod
#pod Not all backends will implement support for all fields or all types of queries.
#pod If it does not implement either, it should "decline" the query with an empty
#pod return.
#pod
#pod The return should be context aware, returning either a
#pod single result or a list of results.
#pod
#pod The result must be formed as follows:
#pod
#pod {
#pod package => 'MOOSE',
#pod version => '2.0802',
#pod uri => "cpan:///distfile/ETHER/Moose-2.0802.tar.gz"
#pod }
#pod
#pod The C<uri> field should be a valid URI. It may be a L<URI::cpan> or any other
#pod URI. (It is up to a client to do something useful with any given URI scheme.)
#pod
#pod =method search_authors (ABSTRACT)
#pod
#pod $result = $index->search_authors( { id => "DAGOLDEN" });
#pod @result = $index->search_authors( \%advanced_query );
#pod
#pod Searches the index for author data such as from the CPAN F<01mailrc.txt> file.
#pod The query must be provided as a hash reference. Valid keys are
#pod
#pod =for :list
#pod * id -- a string, regular expression or code reference
#pod * fullname -- a string, regular expression or code reference
#pod * email -- a string, regular expression or code reference
#pod
#pod If the query term is a string, the query will be for an exact match. If a code
#pod reference, the code will be called with the value of the field for each
#pod potential match. It should return true if it matches.
#pod
#pod Not all backends will implement support for all fields or all types of queries.
#pod If it does not implement either, it should "decline" the query with an empty
#pod return.
#pod
#pod The return should be context aware, returning either a single result or a list
#pod of results.
#pod
#pod The result must be formed as follows:
#pod
#pod {
#pod id => 'DAGOLDEN',
#pod fullname => 'David Golden',
#pod email => 'dagolden@cpan.org',
#pod }
#pod
#pod The C<email> field may not reflect an actual email address. The 01mailrc file
#pod on CPAN often shows "CENSORED" when email addresses are concealed.
#pod
#pod =cut
#--------------------------------------------------------------------------#
# stub methods
#--------------------------------------------------------------------------#
#pod =method index_age
#pod
#pod $epoch = $index->index_age;
#pod
#pod Returns the modification time of the index in epoch seconds. This may not make sense
#pod for some backends. By default it returns the current time.
#pod
#pod =cut
sub index_age { time }
#pod =method refresh_index
#pod
#pod $index->refresh_index;
#pod
#pod This ensures the index source is up to date. For example, a remote
#pod mirror file would be re-downloaded. By default, it does nothing.
#pod
#pod =cut
sub refresh_index { 1 }
#pod =method attributes
#pod
#pod Return attributes and default values as a hash reference. By default
#pod returns an empty hash reference.
#pod
#pod =cut
sub attributes { {} }
#pod =method validate_attributes
#pod
#pod $self->validate_attributes;
#pod
#pod This is called by the constructor to validate any arguments. Subclasses
#pod should override the default one to perform validation. It should not be
#pod called by application code. By default, it does nothing.
#pod
#pod =cut
sub validate_attributes { 1 }
1;
# vim: ts=4 sts=4 sw=4 et:
__END__
=pod
=encoding UTF-8
=head1 NAME
CPAN::Common::Index - Common library for searching CPAN modules, authors and distributions
=head1 VERSION
version 0.010
=head1 SYNOPSIS
use CPAN::Common::Index::Mux::Ordered;
use Data::Dumper;
$index = CPAN::Common::Index::Mux::Ordered->assemble(
MetaDB => {},
Mirror => { mirror => "http://cpan.cpantesters.org" },
);
$result = $index->search_packages( { package => "Moose" } );
print Dumper($result);
# {
# package => 'MOOSE',
# version => '2.0802',
# uri => "cpan:///distfile/ETHER/Moose-2.0802.tar.gz"
# }
=head1 DESCRIPTION
This module provides a common library for working with a variety of CPAN index
services. It is intentionally minimalist, trying to use as few non-core
modules as possible.
The C<CPAN::Common::Index> module is an abstract base class that defines a
common API. Individual backends deliver the API for a particular index.
As shown in the SYNOPSIS, one interesting application is multiplexing -- using
different index backends, querying each in turn, and returning the first
result.
=head1 METHODS
=head2 search_packages (ABSTRACT)
$result = $index->search_packages( { package => "Moose" });
@result = $index->search_packages( \%advanced_query );
Searches the index for a package such as listed in the CPAN
F<02packages.details.txt> file. The query must be provided as a hash
reference. Valid keys are
=over 4
=item *
package -- a string, regular expression or code reference
=item *
version -- a version number or code reference
=item *
dist -- a string, regular expression or code reference
=back
If the query term is a string or version number, the query will be for an exact
match. If a code reference, the code will be called with the value of the
field for each potential match. It should return true if it matches.
Not all backends will implement support for all fields or all types of queries.
If it does not implement either, it should "decline" the query with an empty
return.
The return should be context aware, returning either a
single result or a list of results.
The result must be formed as follows:
{
package => 'MOOSE',
version => '2.0802',
uri => "cpan:///distfile/ETHER/Moose-2.0802.tar.gz"
}
The C<uri> field should be a valid URI. It may be a L<URI::cpan> or any other
URI. (It is up to a client to do something useful with any given URI scheme.)
=head2 search_authors (ABSTRACT)
$result = $index->search_authors( { id => "DAGOLDEN" });
@result = $index->search_authors( \%advanced_query );
Searches the index for author data such as from the CPAN F<01mailrc.txt> file.
The query must be provided as a hash reference. Valid keys are
=over 4
=item *
id -- a string, regular expression or code reference
=item *
fullname -- a string, regular expression or code reference
=item *
email -- a string, regular expression or code reference
=back
If the query term is a string, the query will be for an exact match. If a code
reference, the code will be called with the value of the field for each
potential match. It should return true if it matches.
Not all backends will implement support for all fields or all types of queries.
If it does not implement either, it should "decline" the query with an empty
return.
The return should be context aware, returning either a single result or a list
of results.
The result must be formed as follows:
{
id => 'DAGOLDEN',
fullname => 'David Golden',
email => 'dagolden@cpan.org',
}
The C<email> field may not reflect an actual email address. The 01mailrc file
on CPAN often shows "CENSORED" when email addresses are concealed.
=head2 index_age
$epoch = $index->index_age;
Returns the modification time of the index in epoch seconds. This may not make sense
for some backends. By default it returns the current time.
=head2 refresh_index
$index->refresh_index;
This ensures the index source is up to date. For example, a remote
mirror file would be re-downloaded. By default, it does nothing.
=head2 attributes
Return attributes and default values as a hash reference. By default
returns an empty hash reference.
=head2 validate_attributes
$self->validate_attributes;
This is called by the constructor to validate any arguments. Subclasses
should override the default one to perform validation. It should not be
called by application code. By default, it does nothing.
=for Pod::Coverage method_names_here
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
=head1 SUPPORT
=head2 Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker
at L<https://github.com/Perl-Toolchain-Gang/CPAN-Common-Index/issues>.
You will be notified automatically of any progress on your issue.
=head2 Source Code
This is open source software. The code repository is available for
public review and contribution under the terms of the license.
L<https://github.com/Perl-Toolchain-Gang/CPAN-Common-Index>
git clone https://github.com/Perl-Toolchain-Gang/CPAN-Common-Index.git
=head1 AUTHOR
David Golden <dagolden@cpan.org>
=head1 CONTRIBUTORS
=for stopwords David Golden Helmut Wollmersdorfer Kenichi Ishigaki Shoichi Kaji Tatsuhiko Miyagawa
=over 4
=item *
David Golden <xdg@xdg.me>
=item *
Helmut Wollmersdorfer <helmut@wollmersdorfer.at>
=item *
Kenichi Ishigaki <ishigaki@cpan.org>
=item *
Shoichi Kaji <skaji@cpan.org>
=item *
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
=back
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
=cut
|