App-AYCABTU
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/AYCABTU.pm view on Meta::CPAN
package App::AYCABTU;
our $VERSION = '0.13';
use Mouse;
use Getopt::Long;
use YAML::XS;
use Capture::Tiny 'capture';
has config => (is => 'ro', default => sub{[]});
has file => (is => 'ro', default => 'AYCABTU');
has action => (is => 'ro', default => 'list');
has show => (is => 'ro', default => '');
has tags => (is => 'ro', default => sub{[]});
has names => (is => 'ro', default => sub{[]});
has all => (is => 'ro', default => 0);
has quiet => (is => 'ro', default => 0);
has verbose => (is => 'ro', default => 0);
has args => (is => 'ro', default => sub{[]});
has repos => (is => 'ro', default => sub{[]});
my ($prefix, $error, $quiet, $normal, $verbose);
sub run {
my $self = shift;
my @opts = @_
? @_
: split /\s+/, ($ENV{AYCABTU_DEFAULT_OPTS} || '');
$self->get_options(@opts);
$self->read_config();
$self->select_repos();
if (not @{$self->repos} and not @{$self->names}) {
print "No repositories selected. Try --all.\n";
return;
}
my $action = $self->action;
my $method = "action_$action";
die "Can't perform action '$action'\n"
unless $self->can($method);
for my $entry (@{$self->repos}) {
($prefix, $error, $quiet, $normal, $verbose) = ('') x 5;
$self->$method($entry);
$verbose ||= $normal;
$normal ||= $quiet;
my $msg =
$error ? $error :
$self->verbose ? $verbose :
$self->quiet ? $quiet :
$normal;
$msg = "$prefix$msg\n" if $msg;
print $msg;
}
if (@{$self->names}) {
warn "The following names were not found: @{$self->names}\n";
}
}
sub get_options {
my $self = shift;
local @ARGV = @_;
GetOptions(
'file=s' => sub { $self->file($_[1]) },
'verbose' => sub { $self->verbose(1) },
'quiet' => sub { $self->quiet(1) },
'list' => sub { $self->action('list') },
'update' => sub { $self->action('update') },
'status' => sub { $self->action('status') },
'show=s' => sub { $self->action('show'); $self->show($_[1]) },
'all' => sub { $self->all(1) },
'tags=s' => sub {
my $tags = $_[1] or return;
push @{$self->tags}, [split ',', $tags];
},
'help' => \&help,
);
no warnings;
my $names;
if (1 or not -t stdin) {
$names = [
map {
s!/$!!;
/^(\d+)-(\d+)?$/ ? ($1..$2) :
/^(\d+)$/ ? ($1) :
(-d) ? ($_) :
();
} @ARGV
];
}
else {
$names = [ split /\s+/, do {local $/; <stdin>} ]
}
$self->names($names);
die "Can't locate aycabtu config file '${\ $self->file}'. Use --file=... option\n"
if not -e $self->file and not @{[glob $self->file . '*']};
}
sub read_yaml {
my $self = shift;
my @files = glob($self->file . '*');
my $yaml = '';
local $/;
for my $file (@files) {
open Y, $file;
$yaml .= <Y>;
}
return $yaml;
}
sub read_config {
my $self = shift;
my $yaml = $self->read_yaml();
my $config = YAML::XS::Load($yaml);
$self->config($config);
die $self->file . " must be a YAML sequence of mapping"
if (ref($config) ne 'ARRAY') or grep {
ref ne 'HASH'
} @$config;
my $count = 1;
for my $entry (@$config) {
my $repo = $entry->{repo}
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.574 second using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )