grinder has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use CPANPLUS to query modules. Looking at the documentation, I thought the following would work:

#! /usr/local/bin/perl -wl use strict; use CPANPLUS::Backend; my $cb = CPANPLUS::Backend->new; for my $dist( @ARGV ) { my $res = $cb->search( type => 'module', allow => [], data => [qr/$dist/], ); use Data::Dumper; print Dumper($res); }

Running this with '^Text::' on the command line should spit out all the modules in the Text namespace with their current version. And then I could smoke test them. Except that it doesn't, it crashes with:

Can't locate object method "module" via package "Regexp" at /usr/local +/lib/perl5/site_perl/5.8.7/CPANPLUS/Internals/Search.pm line 166.

But... the documentation for CPANPLUS::Backend::search says:

"search" enables you to search for either module or author objects, based on their data. The "type" you can specify is any of the accessors specified in "CPANPLUS::Module::Author" or "CPANPLUS::Module". "search" will determine by the "type" you specified whether to search by author object or module object.

... and CPANPLUS::Module declares a search module accessor. 'use'ing the module explicitly in the script doesn't fix it either. Can somebody point out the error of my ways?

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re: Using CPANPLUS::Backend to query CPAN metadata
by randyk (Parson) on Sep 22, 2005 at 18:33 UTC
    The examples in CPANPLUS::Internals::Search have the regular expression specifying the search associated with the allow key, as in
    use strict; use CPANPLUS::Backend; my $cb = CPANPLUS::Backend->new; my @dists = ('^Text::'); for my $dist( @dists ) { my @res = $cb->search( type => 'module', allow => [qr/$dist/], ); print $_->module, $/ for @res; }