App-CPAN-Get
view release on metacpan or search on metacpan
Get/MetaCPAN.pm view on Meta::CPAN
package App::CPAN::Get::MetaCPAN;
use strict;
use warnings;
use Class::Utils qw(set_params);
use Cpanel::JSON::XS;
use English;
use Error::Pure qw(err);
use IO::Barf qw(barf);
use LWP::UserAgent;
use Readonly;
use Scalar::Util qw(blessed);
use URI;
Readonly::Scalar our $FASTAPI => qw(https://fastapi.metacpan.org/v1/download_url/);
our $VERSION = 0.14;
sub new {
my ($class, @params) = @_;
# Create object.
my $self = bless {}, $class;
# LWP::User agent object.
$self->{'lwp_user_agent'} = undef;
# Process parameters.
set_params($self, @params);
if (defined $self->{'lwp_user_agent'}) {
if (! blessed($self->{'lwp_user_agent'})
|| ! $self->{'lwp_user_agent'}->isa('LWP::UserAgent')) {
err "Parameter 'lwp_user_agent' must be a ".
'LWP::UserAgent instance.';
}
} else {
$self->{'lwp_user_agent'} = LWP::UserAgent->new;
$self->{'lwp_user_agent'}->agent(__PACKAGE__.'/'.$VERSION);
}
return $self;
}
sub search {
my ($self, $args_hr) = @_;
if (! defined $args_hr
|| ref $args_hr ne 'HASH') {
err 'Bad search options.';
}
if (! exists $args_hr->{'package'}) {
err "Package doesn't present.";
}
my $uri = $self->_construct_uri($args_hr);
my $content = eval {
$self->_fetch($uri);
};
if ($EVAL_ERROR) {
if ($EVAL_ERROR =~ m/^Cannot fetch/ms) {
err "Module '$args_hr->{'package'}' doesn't exist.";
} else {
err $EVAL_ERROR;
Get/MetaCPAN.pm view on Meta::CPAN
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
# }
=head1 EXAMPLE2
=for comment filename=search_module_versions.pl
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
# }
=head1 DEPENDENCIES
L<Class::Utils>,
L<Cpanel::JSON::XS>,
L<English>,
L<Error::Pure>,
L<IO::Barf>,
L<LWP::UserAgent>,
L<Readonly>,
L<Scalar::Util>,
L<URI>.
=head1 REPOSITORY
L<https://github.com/michal-josef-spacek/App-CPAN-Get>
=head1 AUTHOR
Michal Josef Å paÄek L<mailto:skim@cpan.org>
L<http://skim.cz>
=head1 LICENSE AND COPYRIGHT
© 2021-2025 Michal Josef Å paÄek
BSD 2-Clause License
=head1 VERSION
0.14
=cut
( run in 0.602 second using v1.01-cache-2.11-cpan-6aa56a78535 )