App-lcpan-CmdBundle-backpan

 view release on metacpan or  search on metacpan

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

package App::lcpan::Cmd::backpan_author;

our $DATE = '2018-09-13'; # DATE
our $VERSION = '0.001'; # VERSION

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

use Perinci::Object;

require App::lcpan;

our %SPEC;

$SPEC{handle_cmd} = {
    v => 1.1,
    summary => 'Open author page on BackPAN',
    description => <<'_',

Given author with CPAN ID `CPANID`, this will open
`http://BACKPAN_HOST/authors/id/C/CP/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 $c = substr($cpanid, 0, 1);
        my $cp = substr($cpanid, 0, 2);
        my $url = "http://backpan.cpantesters.org/authors/id/$c/$cp/$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 BackPAN

__END__

=pod

=encoding UTF-8

=head1 NAME

App::lcpan::Cmd::backpan_author - Open author page on BackPAN

=head1 VERSION

This document describes version 0.001 of App::lcpan::Cmd::backpan_author (from Perl distribution App-lcpan-CmdBundle-backpan), released on 2018-09-13.

=head1 DESCRIPTION

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

=head1 FUNCTIONS


=head2 handle_cmd

Usage:

 handle_cmd(%args) -> [status, msg, result, meta]

Open author page on BackPAN.

Given author with CPAN ID C<CPANID>, this will open
CL<http://BACKPAN_HOST/authors/id/C/CP/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]>



( run in 3.164 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )