App-cpan2arch

 view release on metacpan or  search on metacpan

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

  :does(App::cpan2arch::CheckPackages)
  :does(App::cpan2arch::WritePkgbuild);

use File::Basename qw< basename >;
use version;

our $VERSION = 'v1.1.2';

field %_env :reader :writer = (
    user_agent       => "App::cpan2arch/$VERSION",
    cache_mcpan_path => '/tmp/mcpan_cache',
    cache_arch_path  => '/tmp/arch_cache',
    cache_expiration => '1d',
);
field $_prog :reader = basename($0);
field %_opts :reader;
field %_args :reader;

method init (@argv)
{
    _exit( $self->_process_env->_process_opts( \@argv ) );

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

    _exit( $self->generate_pkgbuild->write_pkgbuild );

    return 0;
}

# Process environment variables.
method _process_env ()
{
    $_env{packager}         = $ENV{PACKAGER} // 'Your Name <email@domain.tld>';
    $_env{user_agent}       = $ENV{C2A_USER_AGENT}       if defined $ENV{C2A_USER_AGENT};
    $_env{cache_mcpan_path} = $ENV{C2A_CACHE_MCPAN_PATH} if defined $ENV{C2A_CACHE_MCPAN_PATH};
    $_env{cache_arch_path}  = $ENV{C2A_CACHE_ARCH_PATH}  if defined $ENV{C2A_CACHE_ARCH_PATH};
    $_env{cache_expiration} = $ENV{C2A_CACHE_EXPIRATION} if defined $ENV{C2A_CACHE_EXPIRATION};
    $_env{cache_ignore}     = $ENV{C2A_CACHE_IGNORE} ? true : false;
    $_env{debug}            = $ENV{C2A_DEBUG}        ? true : false;

    try {
        if ( $_env{debug} ) {
            require Data::Printer;
            Data::Printer->VERSION('1.002001');
        }

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

        $mua = Mojo::UserAgent::Cached->new(
            $env{debug}
            ? ()
            : ( logger => $logger ),
        );

        # Use CHI as the cache backend.
        {
            my $path =
                $type eq 'mcpan'
              ? $env{cache_mcpan_path}
              : $env{cache_arch_path};

            my $chi;

            $chi = CHI->new(
                driver     => 'File',
                root_dir   => $path,
                expires_in => $env{cache_expiration},
            ) unless $env{cache_ignore};

t/01-offline.t  view on Meta::CPAN

            packager => {
                var     => 'PACKAGER',
                default => $DEFS{packager},
                custom  => 'Alice <alice@domain.tld>',
            },
            user_agent => {
                var     => 'C2A_USER_AGENT',
                default => "$DEFS{class}/$DEFS{ver}",
                custom  => 'App::Foo/v1.0.0',
            },
            cache_mcpan_path => {
                var     => 'C2A_CACHE_MCPAN_PATH',
                default => '/tmp/mcpan_cache',
                custom  => '/tmp/foo_cache',
            },
            cache_arch_path => {
                var     => 'C2A_CACHE_ARCH_PATH',
                default => '/tmp/arch_cache',
                custom  => '/tmp/bar_cache',
            },
            cache_expiration => {

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

subtest 'Unit test' => sub {
    #skip_all;

    # Tests need to set a proper C2A environment + temporary cache.
    my sub get_env_cache ( $t, $path )
    {
        my $temp       = Path::Tiny->tempdir;
        my $cache_path = $temp->child($path)->stringify;

        my $cache_key =
            $path eq 'mcpan_cache' ? 'cache_mcpan_path'
          : $path eq 'arch_cache'  ? 'cache_arch_path'
          :                          ();

        my %env = (
            user_agent       => "$DEFS{class}/$DEFS{ver}",
            $cache_key       => $cache_path,
            cache_expiration => '1d',
            cache_ignore     => $t =~ /\Ano_cache/ ? true : false,
            #debug            => true,
        );



( run in 1.224 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )