App-cpan2arch

 view release on metacpan or  search on metacpan

lib/App/cpan2arch/GetMetadata.pm  view on Meta::CPAN

use Object::Pad 0.825;

package App::cpan2arch::GetMetadata;  # For toolchain compatibility.
role App::cpan2arch::GetMetadata;

use File::Spec::Functions qw< catdir splitdir >;
use Scalar::Util          qw< looks_like_number >;

our $VERSION = 'v1.1.2';

field %_endpoints :reader :writer = (
    module   => 'https://fastapi.metacpan.org/v1/module/',
    release  => 'https://fastapi.metacpan.org/v1/release/',
    download => 'https://fastapi.metacpan.org/v1/download_url/',
);
field $_mua_mcpan :reader;
field %_optionals :reader;
field %_meta      :reader :writer;

# Get CPAN metadata from MetaCPAN's API.
#

lib/App/cpan2arch/GetMetadata.pm  view on Meta::CPAN

    $mua->transactor->name( $env{user_agent} ) if defined $mua;

    return $mua;
}

method _get_module ($module)
{
    $self->_psub;

    my $prog = $self->prog;
    my $url  = $_endpoints{module} . "$module?fields=distribution";
    my $json;

    my $res = do {
        try {
            my %env = $self->env;
            local $ENV{MUAC_NOCACHE} = true if $env{cache_ignore};

            $_mua_mcpan->get($url)->result;
        }
        catch ($e) {

lib/App/cpan2arch/GetMetadata.pm  view on Meta::CPAN

    my %args    = $self->args;
    my $version = $args{version};
    my $prog    = $self->prog;

    my $query = "distribution:$dist%20AND%20";
    $query
      .= defined $version
      ? "version:$version"
      : 'status:latest';

    my $url = $_endpoints{release} . "_search?q=$query";

    my $res = do {
        try {
            my %env = $self->env;
            local $ENV{MUAC_NOCACHE} = true if $env{cache_ignore};

            $_mua_mcpan->get($url)->result;
        }
        catch ($e) {
            warn $e;

lib/App/cpan2arch/MergePrereqs.pm  view on Meta::CPAN


# Fetch all modules distributions concurrently.
method _fetch (@prereqs)
{
    $self->_psub;

    require Mojo::Promise;

    my $prog      = $self->prog;
    my $mua_mcpan = $self->mua_mcpan;
    my %endpoints = $self->endpoints;

    my %env = $self->env;
    local $ENV{MUAC_NOCACHE} = true if $env{cache_ignore};

    # Fetch three dists at a time using the download_url endpoint.
    #
    # References:
    #   https://github.com/metacpan/metacpan-api/blob/master/docs/API-docs.md#download_urlmodule.
    #   https://metacpan.org/release/MIYAGAWA/App-cpanminus-1.7049/source/lib/App/cpanminus/fatscript.pm#L926
    #   https://github.com/metacpan/MetaCPAN-Client/blob/396ba371317f114db04967c90be64bb46fd7fd2c/lib/MetaCPAN/Client.pm#L217
    return Mojo::Promise->map(
        { concurrency => 3 },
        sub ($prereq) {
            my $module  = $prereq->{module};
            my $version = $prereq->{version};
            my $url     = $endpoints{download} . $module;
            my $query;

            $query  = 'version=' . $version if $version;       # Ignore 0 versions.
            $url   .= '?' . $query          if defined $query;

            $mua_mcpan->get_p($url);
        },
        @prereqs,
      )
      ->then(

t/02-online.t  view on Meta::CPAN

                        ( my $env, $cache_path ) = get_env_cache( $t, 'mcpan_cache' );
                        $c2a->set_env( $env->%* );
                    }

                    my @argv = $name;
                    push @argv, $VER if $t eq 'normal_dist' || $t eq 'no_cache_dist';
                    $c2a->_process_opts( \@argv );

                    # Error
                    if ( $t =~ /\Abogus_/ ) {
                        my %endpoints = $c2a->endpoints;

                        if ( $t eq 'bogus_mod_end' ) {
                            $endpoints{module} = $BOGUS_END;
                            $c2a->set_endpoints(%endpoints);
                        }
                        elsif ( $t eq 'bogus_rel_end' ) {
                            $endpoints{release} = $BOGUS_END;
                            $c2a->set_endpoints(%endpoints);
                        }

                        my ( $stderr, @ret ) = capture_stderr {
                            return $c2a->get_metadata;
                        };

                        is(
                            $ret[0], number(1),
                            'return value (error)',
                        );

t/02-online.t  view on Meta::CPAN


                if ($has_cache_mods) {
                    ( my $env, $cache_path ) = get_env_cache( $t, 'mcpan_cache' );
                    $c2a->set_env( $env->%* );
                }

                $c2a->_init_mua_mcpan;
                $c2a->set_meta( $expected->{$DIST}{meta}->%* );

                if ( $t eq 'bogus_url' ) {
                    my %endpoints = $c2a->endpoints;
                    $endpoints{download} = $name;
                    $c2a->set_endpoints(%endpoints);

                    my ( $stderr, @ret ) = capture_stderr {
                        return $c2a->merge_prereqs;
                    };
                    my @fetch_errors = $c2a->fetch_errors;

                    is(
                        scalar @fetch_errors, number_gt(0),
                        'has error message',
                    );



( run in 1.395 second using v1.01-cache-2.11-cpan-9789f410c06 )