App-Download
view release on metacpan or search on metacpan
bin/download view on Meta::CPAN
use File::Temp qw(tempdir);
use Getopt::Long::Descriptive;
use Term::ANSIColor qw(colored);
# global vars
# subs
sub exit_with_error_message {
my ($msg) = @_;
say colored($msg, 'red');
exit 1;
}
sub run_cmd {
my ($cmd) = @_;
say colored('$ ' . $cmd, 'green');
my $exit_code = system($cmd);
if ($exit_code != '0') {
exit_with_error_message('Error. Command exited with non zero exit code');
}
}
sub mkdir_recursive {
my $path = shift;
mkdir_recursive(dirname($path)) if not -d dirname($path);
bin/download view on Meta::CPAN
}
my $tempdir = tempdir( CLEANUP => 1 );
run_cmd("git clone $url $tempdir");
if ($opt->commit() ne 'HEAD') {
run_cmd("cd $tempdir; git checkout " . $opt->commit());
}
say colored('Copying files', 'green');
my $cp_count = 0;
find(
{
wanted => sub {
if (-f $File::Find::name) {
$File::Find::name =~ m{$tempdir/(.*)};
my $relative_name = $1;
my $re = $opt->include_re();
if ($relative_name =~ /$re/) {
say $relative_name;
# http://stackoverflow.com/questions/229357/what-is-the-best-way-in-perl-to-copy-files-into-a-yet-to-be-created-directory-tr/229382#229382
mkdir_and_copy(
$File::Find::name,
$opt->to_dir() . '/' . $relative_name,
);
$cp_count++;
}
}
( run in 2.446 seconds using v1.01-cache-2.11-cpan-d7a12ab2c7f )