App-Wax

 view release on metacpan or  search on metacpan

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

package App::Wax;

use 5.014000;

use Digest::SHA qw(sha1_hex);
use File::Slurper qw(read_text write_text);
use File::Spec;
use File::Temp;
use Function::Parameters qw(fun method);
use Getopt::Long qw(GetOptionsFromArray :config posix_default require_order bundling no_auto_abbrev no_ignore_case);
use IPC::System::Simple qw(EXIT_ANY $EXITVAL systemx);
use LWP::UserAgent;
use MIME::Types;
use Mouse;
use Parallel::parallel_map qw(parallel_map);
use Pod::Usage qw(pod2usage);
use Try::Tiny qw(try catch);
use URI::Split qw(uri_split);

# NOTE this is the version of the *command* rather than the *module*, i.e.
# breaking API changes may occur here which aren't reflected in the SemVer since
# they don't break the behavior of the command
#
# XXX this declaration must be on a single line
# https://metacpan.org/pod/version#How-to-declare()-a-dotted-decimal-version
use version; our $VERSION = version->declare('v2.5.0');

# defaults
use constant {
    CACHE              => 0,
    DEFAULT_USER_AGENT => 'Mozilla/5.0 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0',
    ENV_PROXY          => 1,
    ENV_USER_AGENT     => $ENV{WAX_USER_AGENT},
    EXTENSION          => qr/.(\.(?:(tar\.(?:bz|bz2|gz|lzo|Z))|(?:[ch]\+\+)|(?:\w+)))$/i,
    INDEX              => '%s.index.txt',
    MIRROR             => 0,
    NAME               => 'wax',
    SEPARATOR          => '--',
    TEMPLATE           => 'XXXXXXXX',
    TIMEOUT            => 60,
    VERBOSE            => 0,
};

use constant USER_AGENT => ENV_USER_AGENT || DEFAULT_USER_AGENT;

# RFC 2616: "If the media type remains unknown, the recipient SHOULD treat
# it as type 'application/octet-stream'."
use constant DEFAULT_CONTENT_TYPE => 'application/octet-stream';

# resources with these mime-types may have their extension inferred from the
# path part of their URI
use constant INFER_EXTENSION => {
    'text/plain'               => 1,
    'application/octet-stream' => 1,
    'binary/octet-stream'      => 1,
};

# errors
use constant {
    OK                  =>  0,
    E_DOWNLOAD          => -1,
    E_INVALID_DIRECTORY => -2,
    E_INVALID_OPTIONS   => -3,
    E_NO_COMMAND        => -4,
};

has app_name => (
    is      => 'rw',
    isa     => 'Str',
    default => NAME,
);

has cache => (
    is      => 'rw',
    isa     => 'Bool',
    default => CACHE,
    trigger => \&_check_keep,



( run in 1.342 second using v1.01-cache-2.11-cpan-99c4e6809bf )