App-MechaCPAN
view release on metacpan or search on metacpan
lib/App/MechaCPAN.pm view on Meta::CPAN
package App::MechaCPAN;
use v5.14;
use strict;
use Cwd qw/cwd/;
use Carp;
use Config;
use Symbol qw/geniosym/;
use autodie;
use Term::ANSIColor qw//;
use IPC::Open3;
use IO::Select;
use List::Util qw/first/;
use Scalar::Util qw/blessed openhandle/;
use File::Temp qw/tempfile tempdir/;
use File::Fetch;
use File::Spec qw//;
use Getopt::Long qw//;
use Exporter qw/import/;
BEGIN
{
our @EXPORT_OK = qw/
url_re git_re git_extract_re
has_git has_updated_git min_git_ver
can_https
logmsg info success error
dest_dir get_project_dir
fetch_file inflate_archive
humane_tmpname humane_tmpfile humane_tmpdir
parse_cpanfile
run restart_script
rel_start_to_abs
/;
our %EXPORT_TAGS = ( go => [@EXPORT_OK] );
}
our $VERSION = '0.30';
require App::MechaCPAN::Perl;
require App::MechaCPAN::Install;
require App::MechaCPAN::Deploy;
my $loaded_at_compile;
my $restarted_key = 'APP_MECHACPAN_RESTARTED';
my $is_restarted_process = delete $ENV{$restarted_key};
INIT
{
$loaded_at_compile = 1;
}
$loaded_at_compile //= 0;
our @args = (
'diag-run!',
'verbose|v!',
'quiet|q!',
'no-log!',
'directory|d=s',
'build-reusable-perl!',
);
# Timeout when there's no output in seconds
our $TIMEOUT = $ENV{MECHACPAN_TIMEOUT} // 60;
our $VERBOSE; # Print output from sub commands to STDERR
our $QUIET; # Do not print any progress to STDERR
our $LOGFH; # File handle to send the logs to
our $LOG_ON = 1; # Default if to log or not
our $PROJ_DIR; # The directory given with -d or pwd if not provided
sub main
{
my @argv = @_;
if ( $0 =~ m/zhuli/ )
{
if ( $argv[0] =~ m/^do the thing/i )
{
success( "zhuli$$", 'Running deployment' )
unless $is_restarted_process;
$argv[0] = 'deploy';
}
if ( $argv[0] =~ m/^do$/i
&& $argv[1] =~ m/^the$/i
&& $argv[2] =~ m/^thing$/i )
lib/App/MechaCPAN.pm view on Meta::CPAN
}
if ( $options->{'diag-run'} )
{
warn "Would run '$cmd'\n";
chdir $orig_dir;
return 0;
}
$options->{is_restarted_process} = $is_restarted_process;
if ( defined $munge )
{
@argv = $pkg->$munge( $options, @argv );
}
my $dest_dir = &dest_dir;
if ( !-d $dest_dir )
{
mkdir $dest_dir;
}
_setup_log($dest_dir)
unless $options->{'no-log'};
local $@;
my $ret = eval { $pkg->$action( $options, @argv ) || 0; };
chdir $orig_dir;
if ( !defined $ret )
{
error($@);
return -1;
}
return $ret;
}
sub _git_str
{
state $_git_str;
if ( !defined $_git_str )
{
$_git_str = '';
my $git_version_str = eval { run(qw/git --version/); };
if ( defined $git_version_str )
{
($_git_str) = $git_version_str =~ m/git version (\d+[.]\d+[.]\d+)/;
}
}
return $_git_str;
}
sub min_git_ver
{
return '1.7.7';
}
sub has_updated_git
{
my $git_version_str = _git_str;
if ($git_version_str)
{
use version 0.77;
if ( version->parse($git_version_str) >= version->parse(min_git_ver) )
{
return 1;
}
}
return;
}
sub has_git
{
return _git_str && has_updated_git;
}
# Give a list of https-incapable File::Fetch methods when https is unavailable
sub _https_blacklist
{
require Module::Load::Conditional;
state $can_https
= Module::Load::Conditional::can_load( modules => 'IO::Socket::SSL' );
if ( !$can_https )
{
return qw/lwp httptiny httplite/;
}
return ();
}
sub can_https
{
state $can_https;
# track the blacklist for testing
state $ff_blacklist;
undef $can_https
if $File::Fetch::BLACKLIST ne $ff_blacklist;
if ( !defined $can_https )
{
my $test_url = 'https://get.mechacpan.us/latest';
my $test_str = '';
local $File::Fetch::WARN;
local $@;
my $ff = File::Fetch->new( uri => $test_url );
return 0
if !defined $ff;
$ff_blacklist = $File::Fetch::BLACKLIST;
# Make sure not to use methods that can't handle https
local $File::Fetch::BLACKLIST = [ @$ff_blacklist, _https_blacklist ];
$ff->scheme('http');
$can_https = defined $ff->fetch( to => \$test_str );
}
return $can_https;
}
sub url_re
{
state $url_re = qr[
^
(?: ftp | http | https | file )
: //
]xmsi;
return $url_re;
}
( run in 1.395 second using v1.01-cache-2.11-cpan-39bf76dae61 )