WWW::CPAN->query()

ferreira on 2008-01-14T22:51:06

WWW::CPAN is a work in progress (slow progress, to be honest). At 0.004 release, its API got one more method, query(). The whole API is:

  • new - good old constructor
  • fetch_distmeta - grab META.yml (META.json) from CPAN distributions
  • query - do simple queries and get the result as Perl data

Ain't that promising? Everyone will use it when 0.999 release arrives. (Yes, updates are by +0.001 increments.)


API

izut on 2008-01-15T06:51:25

Hi Adriano,

I was reading WWW::CPAN API, and I have one suggestion to the API: change the method name fetch_distmeta() to get_meta().

This reflects the fact that you're dealing with CPAN, and the word 'meta' is used by modules on CPAN, so you can avoid the word 'dist' there - CPAN deals with software distribution. And fetch IMHO seems to be too related with the medium (and it is longer than get).

For example:


my $cpan = WWW::CPAN->new;
my $meta = $cpan->get_meta({ dist => 'WWW::CPAN' });


Is more clear and less polluted than:


my $cpan = WWW::CPAN->new;
my $meta = $cpan->fetch_distmeta({ dist => "WWW::CPAN" });


Other possibility would have a WWW::CPAN::Dist class, which is a stub for actually retrieving data from CPAN, like:


my $cpan = WWW::CPAN->new;

for my $d (qw( WWW::CPAN )) {
        my $meta = $cpan->dist('WWW::CPAN')->get_meta; ...
}


What do you think?

Re:API

ferreira on 2008-01-15T11:14:41

Those sound like very elegant ideas and I will think harder about them in the next days. The reason I went with "fetch_distmeta" was to anticipate the occurrence of other meta data beyond CPAN distributions, like authors. And "fetch" was chosen instead of "get" because the latter reminded me only simple accessor rather than a real action to retrieve some data. But I am thinking about it. Thanks for your feedback, Igor.