logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

MetaCPAN::Client - A comprehensive, DWIM-featured client to the MetaCPAN API

Attributes

request
       Internal attribute representing the request object making the request to MetaCPAN and analyzing the
       results. You probably don't want to set this, nor should you have any usage of it.

   ua
       If provided, MetaCPAN::Client::Request will use the user agent object instead of the default, which is
       HTTP::Tiny.

       Then it can be used to fetch the user agent object used by MetaCPAN::Client::Request.

   domain
       If given, will be used to alter the API domain.

   debug
       If given, errors will include some low-level detailed message.

Authors

       •   Sawyer X <xsawyerx@cpan.org>

       •   Mickey Nasriachi <mickey@cpan.org>

Description

       This is a hopefully-complete API-compliant client to MetaCPAN (<https://metacpan.org>) with DWIM
       capabilities, to make your life easier.

Design

       This module has three purposes:

       •   Provide 100% of the MetaCPAN API

           This  module  will be updated regularly on every MetaCPAN API change, and intends to provide the user
           with as much of the API as possible, no shortcuts. If it's documented in the API, you should be  able
           to do it.

           Because  of this design decision, this module has an official MetaCPAN namespace with the blessing of
           the MetaCPAN developers.

           Notice this module currently only provides the beta API, not the old soon-to-be-deprecated API.

       •   Be lightweight, to allow flexible usage

           While many modules would help make writing easier, it's important  to  take  into  account  how  they
           affect your compile-time, run-time, overall memory consumption, and CPU usage.

           By  providing  a slim interface implementation, more users are able to use this module, such as long-
           running processes (like daemons), CLI or GUI applications, cron jobs, and more.

       •   DWIM

           While it's possible to access the methods defined by the API spec, there's still  a  matter  of  what
           you're  really  trying to achieve. For example, when searching for "Dave", you want to find both DaveCross and DaveRolsky (and any other Dave), but you also want to search for a PAUSE ID  of  DAVE,  if
           one exists.

           This  is where DWIM comes in. This module provides you with additional generic methods which will try
           to do what they think you want.

           Of course, this does not prevent you from manually using the API methods. You still have full control
           over that, if that's what you wish.

           You can (and should) read up on the general methods, which will  explain  how  their  DWIMish  nature
           works, and what searches they run.

Methods

author
           my $author = $mcpan->author('XSAWYERX');
           my $author = $mcpan->author($search_spec);

       Finds an author by either its PAUSE ID or by a search spec defined by a hash reference. Since it is
       common to many other searches, it is explained below under "SEARCH SPEC".

       Returns a MetaCPAN::Client::Author object on a simple search (PAUSE ID), or a MetaCPAN::Client::ResultSet
       object populated with MetaCPAN::Client::Author objects on a complex (search spec based) search.

   cover
           my $cover = $mcpan->cover('Moose-2.2007');

       Returns a MetaCPAN::Client::Cover object.

   distribution
           my $dist = $mcpan->distribution('MetaCPAN-Client');
           my $dist = $mcpan->distribution($search_spec);

       Finds a distribution by either its distribution name or by a search spec defined by a hash reference.
       Since it is common to many other searches, it is explained below under "SEARCH SPEC".

       Returns a MetaCPAN::Client::Distribution object on a simple search (distribution name), or a
       MetaCPAN::Client::ResultSet object populated with MetaCPAN::Client::Distribution objects on a complex
       (search spec based) search.

   file
       Returns a MetaCPAN::Client::File object.

   favorite
           my $favorite = $mcpan->favorite({ distribution => 'Moose' });

       Returns a MetaCPAN::Client::ResultSet object containing MetaCPAN::Client::Favorite results.

   rating
           my $rating = $mcpan->rating({ distribution => 'Moose' });

       Returns a MetaCPAN::Client::ResultSet object containing MetaCPAN::Client::Rating results.

   release
           my $release = $mcpan->release('MetaCPAN-Client');
           my $release = $mcpan->release($search_spec);

       Finds a release by either its distribution name or by a search spec defined by a hash reference. Since it
       is common to many other searches, it is explained below under "SEARCH SPEC".

       Returns a MetaCPAN::Client::Release object on a simple search (release name), or a
       MetaCPAN::Client::ResultSet object populated with MetaCPAN::Client::Release objects on a complex (search
       spec based) search.

   mirror
           my $mirror = $mcpan->mirror('kr.freebsd.org');

       Returns a MetaCPAN::Client::Mirror object.

   module
           my $module = $mcpan->module('MetaCPAN::Client');
           my $module = $mcpan->module($search_spec);

       Finds a module by either its module name or by a search spec defined by a hash reference. Since it is
       common to many other searches, it is explained below under "SEARCH SPEC".

       Returns a MetaCPAN::Client::Module object on a simple search (module name), or a
       MetaCPAN::Client::ResultSet object populated with MetaCPAN::Client::Module objects on a complex (search
       spec based) search.

   package
           my $package = $mcpan->package('MooseX::Types');

       Returns a MetaCPAN::Client::Package object.

   permission
           my $permission = $mcpan->permission('MooseX::Types');

       Returns a MetaCPAN::Client::Permission object.

   reverse_dependencies
           my $deps = $mcpan->reverse_dependencies('Search::Elasticsearch');

       all MetaCPAN::Client::Release objects of releases that are directly dependent on a given module, returned
       as MetaCPAN::Client::ResultSet.

   rev_deps
       Alias to "reverse_dependencies" described above.

   autocomplete
           my $ac = $mcpan->autocomplete('Danc');

       Call the search/autocomplete endpoint with a query string.

       Returns an array reference.

   autocomplete_suggest
           my $ac = $mcpan->autocomplete_suggest('Moo');

       Call the search/autocomplete/suggest endpoint with a query string.

       Returns an array reference.

   recent
           my $recent = $mcpan->recent(10);
           my $recent = $mcpan->recent('today');

       return the latest N releases, or all releases from today.

       returns a MetaCPAN::Client::ResultSet of MetaCPAN::Client::Release.

   pod
       Get POD for given file/module name.  returns a MetaCPAN::Client::Pod object, which supports various
       output formats (html, plain, x_pod & x_markdown).

           my $pod = $mcpan->pod('Moo')->html;
           my $pod = $mcpan->pod('Moo', { url_prefix => $prefix })->html;

   download_url
       Retrieve information from the 'download_url' endpoint

           my $download_url = $mcpan->download_url($distro, [$version_or_range, $dev]);

           # request the last available version
           my $download_url = $mcpan->download_url('Moose');

           # request an older version
           my $download_url = $mcpan->download_url('Moose', '1.01');

           # using a range
           my $download_url = $mcpan->download_url('Moose', '<=1.01');
           my $download_url = $mcpan->download_url('Moose', '>1.01,<=2.00');

       Range operators are '== != <= >= < > !'.  You can use a comma ',' to add multiple rules.

           # requesting dev release
           my $download_url = $mcpan->download_url('Moose', '>1.01', 1);

       Returns a MetaCPAN::Client::DownloadURL object

   all
       Retrieve all matches for authors/modules/distributions/favorites or releases.

           my $all_releases = $mcpan->all('releases')

       When called with a second parameter containing a hash ref, will support the following keys:

       fields

       See SEARCH PARAMS.

          my $all_releases = $mcpan->all('releases', { fields => [...] })

       _source

       See SEARCH PARAMS.

          my $all_releases = $mcpan->all('releases', { _source => [...] })

       es_filter

       Pass a raw Elasticsearch filter structure to reduce the number of elements returned by the query.

           my $some_releases = $mcpan->all('releases', { es_filter => {...} })

   BUILDARGS
       Internal construction wrapper. Do not use.

Name

       MetaCPAN::Client - A comprehensive, DWIM-featured client to the MetaCPAN API

Synopsis

           # simple usage
           my $mcpan  = MetaCPAN::Client->new();
           my $author = $mcpan->author('XSAWYERX');
           my $dist   = $mcpan->distribution('MetaCPAN-Client');

           # advanced usage with cache (contributed by Kent Fredric)
           use CHI;
           use WWW::Mechanize::Cached;
           use HTTP::Tiny::Mech;
           use MetaCPAN::Client;

           my $mcpan = MetaCPAN::Client->new(
             ua => HTTP::Tiny::Mech->new(
               mechua => WWW::Mechanize::Cached->new(
                 cache => CHI->new(
                   driver   => 'File',
                   root_dir => '/tmp/metacpan-cache',
                 ),
               ),
             ),
           );

           # now $mcpan caches results

Version

       version 2.033000

See Also