App-DuckPAN
view release on metacpan or search on metacpan
lib/App/DuckPAN.pm view on Meta::CPAN
use HTTP::Status;
use List::Util qw( first max );
use LWP::UserAgent;
use LWP::Simple;
use Parse::CPAN::Packages::Fast;
use File::Temp qw/ :POSIX /;
use Term::ANSIColor;
use Term::UI;
use Term::ReadLine;
use Carp;
use Encode;
use Perl::Version;
use Path::Tiny;
use open qw/:std :utf8/;
use App::DuckPAN::Cmd::Help;
use DDG::Meta::Data;
no warnings 'uninitialized';
option dev_version => (
is => 'ro',
default => 9.999,
doc => 'Version used when using unreleased code, e.g. git repos'
);
option check => (
is => 'ro',
lazy => 1,
negativable => 1,
default => sub { 1 },
doc => 'perform requirements checks. turn off with --no-check',
);
option empty => (
is => 'ro',
lazy => 1,
short => 'e',
default => sub { 0 },
doc => 'empty duckpan cache at start-up',
);
has cachesec => (
is => 'ro',
lazy => 1,
default => sub { 60 * 60 * 4 }, # 4 hours by default
);
option colors => (
is => 'ro',
lazy => 1,
negativable => 1,
default => sub { 1 },
doc => 'use color output. turn off with --no-colors',
);
option verbose => (
is => 'ro',
lazy => 1,
short => 'v|debug',
default => sub { 0 },
doc => 'provide expanded output during operation',
);
has duckpan_packages => (
is => 'ro',
lazy => 1,
builder => 1,
);
sub _build_duckpan_packages {
my $self = shift;
my $gz = '02packages.details.txt.gz';
my $package_url = join('/', $self->duckpan, 'modules', $gz);
my $mirror_to = $self->cfg->cache_path->child($gz);
if (is_error(mirror($package_url, $mirror_to))) {
$self->emit_and_exit(1, "Cannot download $package_url");
}
return Parse::CPAN::Packages::Fast->new($mirror_to->stringify);
}
option duckpan => (
is => 'ro',
lazy => 1,
default => sub { 'http://duckpan.org/' },
doc => 'URI for the duckpan package server. defaults to "https://duckpan.org/"',
);
sub _ua_string {
my ($self) = @_;
my $class = ref $self || $self;
my $version = $class->VERSION || $self->dev_version;
return "$class/$version";
}
option http_proxy => (
is => 'ro',
predicate => 1,
doc => 'proxy to use for outbound HTTP requests',
);
option config => (
is => 'ro',
predicate => 1,
doc => 'path to config directory. defaults to "~/.duckpan/config"',
);
option cache => (
is => 'ro',
predicate => 1,
doc => 'path to cache directory. defaults to "~/.duckpan/cache"',
);
has term => (
is => 'ro',
lazy => 1,
builder => 1,
);
( run in 0.620 second using v1.01-cache-2.11-cpan-97f6503c9c8 )