App-lcpan-CmdBundle-metacpan

 view release on metacpan or  search on metacpan

lib/App/lcpan/Cmd/metacpan_dist.pm  view on Meta::CPAN

package App::lcpan::Cmd::metacpan_dist;

use 5.010001;
use strict;
use warnings;
use Log::ger;

use Perinci::Object;

require App::lcpan;

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2022-03-27'; # DATE
our $DIST = 'App-lcpan-CmdBundle-metacpan'; # DIST
our $VERSION = '0.008'; # VERSION

our %SPEC;

$SPEC{handle_cmd} = {
    v => 1.1,
    summary => 'Open distribution POD on MetaCPAN',
    description => <<'_',

Given distribution `DIST`, this will open
`https://metacpan.org/release/AUTHOR/DIST-VERSION`. `DIST` will first be checked
for existence in local index database.

_
    args => {
        %App::lcpan::common_args,
        %App::lcpan::dists_args,
    },
};
sub handle_cmd {
    my %args = @_;

    my $state = App::lcpan::_init(\%args, 'ro');
    my $dbh = $state->{dbh};

    my $envres = envresmulti();
    for my $dist (@{ $args{dists} }) {
        my ($file_id, $cpanid, $version) = $dbh->selectrow_array(
            "SELECT id, cpanid, dist_version FROM file WHERE dist_name=? AND is_latest_dist", {}, $dist);
        $file_id or do {
            $envres->add_result(404, "No such dist '$dist'");
            next;
        };

        require Browser::Open;
        my $url = "https://metacpan.org/release/$cpanid/$dist-$version";
        my $err = Browser::Open::open_browser($url);
        if ($err) {
            $envres->add_result(500, "Can't open browser for URL $url");
        } else {
            $envres->add_result(200, "OK");
        }
    }
    $envres->as_struct;
}

1;
# ABSTRACT: Open distribution POD on MetaCPAN

__END__

=pod

=encoding UTF-8

=head1 NAME

App::lcpan::Cmd::metacpan_dist - Open distribution POD on MetaCPAN

=head1 VERSION

This document describes version 0.008 of App::lcpan::Cmd::metacpan_dist (from Perl distribution App-lcpan-CmdBundle-metacpan), released on 2022-03-27.

=head1 DESCRIPTION

This module handles the L<lcpan> subcommand C<metacpan-dist>.

=head1 FUNCTIONS


=head2 handle_cmd

Usage:

 handle_cmd(%args) -> [$status_code, $reason, $payload, \%result_meta]

Open distribution POD on MetaCPAN.

Given distribution C<DIST>, this will open
CL<https://metacpan.org/release/AUTHOR/DIST-VERSION>. C<DIST> will first be checked
for existence in local index database.

This function is not exported.

Arguments ('*' denotes required arguments):

=over 4

=item * B<cpan> => I<dirname>

Location of your local CPAN mirror, e.g. E<sol>pathE<sol>toE<sol>cpan.



( run in 2.386 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )