NAME

App::CPAN::Get::MetaCPAN - Helper class to work with MetaCPAN distribution files.

SYNOPSIS

use App::CPAN::Get::MetaCPAN;

my $obj = App::CPAN::Get::MetaCPAN->new(%params);
my $content_hr = $obj->search($args_hr);
$obj->save($uri, $file);

METHODS

new

my $obj = App::CPAN::Get::MetaCPAN->new(%params);

Constructor.

  • lwp_user_agent

    LWP::User agent object.

    Default value is undef.

Returns instance of object.

my $content_hr = $obj->search($args_hr);

Search on MetaCPAN API.

Variable $args_hr is reference to hash with keys:

  • include_dev

    Flag that means development versions.

  • package

    Package name (e.g. App::Pod::Example).

  • version

    Version of package.

  • version_range

    Version range (e.g. >0.15,<0.17).

Result is reference to hash with information about download URL. Keys are checksum_md5, date, download_url, version, status, release and checksum_sha256.

Returns reference to hash.

save

$obj->save($uri, $file);

Save URI to file.

Returns undef.

ERRORS

new():
        From Class::Utils::set_params():
                Unknown parameter '%s'.
        Parameter 'lwp_user_agent' must be a 'LWP::UserAgent instance.

search():
        Bad search options.
        Cannot connect to CPAN server.
        Module '%s' doesn't exist.
        Package doesn't present.

save():
        Cannot connect to CPAN server.
                HTTP code: %s
                HTTP message: %s
        Cannot fetch '%s' URI.
                HTTP code: %s
                HTTP message: %s
        Cannot fetch '%s'.
                HTTP code: %s
                HTTP message: %s

EXAMPLE1

use strict;
use warnings;

use App::CPAN::Get::MetaCPAN;
use Data::Printer;

my $obj = App::CPAN::Get::MetaCPAN->new;

my $content_hr = $obj->search({
        'package' => 'App::Pod::Example',
        'version' => '0.20',
});

p $content_hr;

# Output (2024/06/23):
# {
#     checksum_md5      "dcc4d6f0794c6fc985a6b3c9bd22f88d",
#     checksum_sha256   "ca71d7d17fe5ea1cd710b9fce554a1219e911baefcaa8ce1ac9c09425f6ae445",
#     date              "2023-03-29T09:57:36" (dualvar: 2023),
#     download_url      "https://cpan.metacpan.org/authors/id/S/SK/SKIM/App-Pod-Example-0.20.tar.gz",
#     release           "App-Pod-Example-0.20",
#     status            "latest",
#     version           0.2
# }

EXAMPLE2

use strict;
use warnings;

use App::CPAN::Get::MetaCPAN;
use Data::Printer;

my $obj = App::CPAN::Get::MetaCPAN->new;

my $content_hr = $obj->search({
        'package' => 'App::Pod::Example',
        'version_range' => '>0.18,<=0.40',
});

p $content_hr;

# Output (2024/06/23):
# {
#     checksum_md5      "dcc4d6f0794c6fc985a6b3c9bd22f88d",
#     checksum_sha256   "ca71d7d17fe5ea1cd710b9fce554a1219e911baefcaa8ce1ac9c09425f6ae445",
#     date              "2023-03-29T09:57:36" (dualvar: 2023),
#     download_url      "https://cpan.metacpan.org/authors/id/S/SK/SKIM/App-Pod-Example-0.20.tar.gz",
#     release           "App-Pod-Example-0.20",
#     status            "latest",
#     version           0.2
# }

DEPENDENCIES

Class::Utils, Cpanel::JSON::XS, English, Error::Pure, IO::Barf, LWP::UserAgent, Readonly, Scalar::Util, URI.

REPOSITORY

https://github.com/michal-josef-spacek/App-CPAN-Get

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© 2021-2024 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.12