App-lcpan-CmdBundle-metacpan

 view release on metacpan or  search on metacpan

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

package App::lcpan::Cmd::metacpan_author;

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 author page on MetaCPAN',
    description => <<'_',

Given author with CPAN ID `CPANID`, this will open
`https://metacpan.org/author/CPANID`. `CPANID` will first be checked for
existence in local index database.

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

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

    my $envres = envresmulti();
    for my $author (@{ $args{authors} }) {
        my ($cpanid) = $dbh->selectrow_array(
            "SELECT cpanid FROM author WHERE cpanid=?", {}, uc $author);
        defined $cpanid or do {
            $envres->add_result(404, "No such author '$author'");
            next;
        };

        require Browser::Open;
        my $url = "https://metacpan.org/author/$cpanid";
        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 author page on MetaCPAN

__END__

=pod

=encoding UTF-8

=head1 NAME

App::lcpan::Cmd::metacpan_author - Open author page on MetaCPAN

=head1 VERSION

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

=head1 DESCRIPTION

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

=head1 FUNCTIONS


=head2 handle_cmd

Usage:

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

Open author page on MetaCPAN.

Given author with CPAN ID C<CPANID>, this will open
CL<https://metacpan.org/author/CPANID>. C<CPANID> will first be checked for
existence in local index database.

This function is not exported.

Arguments ('*' denotes required arguments):

=over 4

=item * B<authors>* => I<array[str]>

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



( run in 1.054 second using v1.01-cache-2.11-cpan-5735350b133 )