The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CPAN::02Packages::Search - Search packages in 02packages.details.txt

SYNOPSIS

use CPAN::02Packages::Search;

my $index = CPAN::02Packages::Search->new(file => '/path/to/02packages.details.txt');

my $result1 = $index->search('Plack'); # { version => "1.0048", path => "M/MI/MIYAGAWA/Plack-1.0048.tar.gz" }
my $result2 = $index->search('Does_Not_Exist'); # undef

DESCRIPTION

CPAN::02Packages::Search allows you to search packages in the de facto standard CPAN index file 02packages.details.txt.

MOTIVATION

We can already search packages in 02packages.details.txt by the excellent module CPAN::Common::Index::Mirror. Its functionality is not only searching packages, but also searching authors and even fetching/caching index files.

As an author of CPAN clients, I just want to search packages in 02packages.details.txt. So I ended up extracting functionality of searching packages from CPAN::Common::Index::Mirror as CPAN::02Packages::Search.

PERFORMANCE

CPAN::Common::Index::Mirror and CPAN::02Packages::Search use Search::Dict, which implements binary search. A simple benchmark shows that CPAN::02Packages::Search is 422 times faster than naive search.

❯ perl bench/bench.pl
               Rate naive_search   our_search
naive_search 4.13/s           --        -100%
our_search   1752/s       42291%           --

See bench/bench.pl for details.

SEE ALSO

CPAN::Common::Index::Mirror

Search::Dict

https://www.cpan.org/modules/04pause.html

AUTHOR

Shoichi Kaji <skaji@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2021 Shoichi Kaji <skaji@cpan.org>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.