App-plx
view release on metacpan or search on metacpan
lib/App/plx.pm view on Meta::CPAN
sub show_config_libspec {
my @ent = @{$self->layout_libspec_config};
my $max = List::Util::max(map length($_->[0]), @ent);
say sprintf("%-${max}s %s", @$_) for @ent;
}
sub run_named_config_add {
my ($self, $type, $name, $value) = @_;
barf "plx --config ${type} add <name> <value>"
unless $name and defined($value);
unless (-d (my $dir = $self->layout_config_dir($type))) {
mkdir($dir) or die "Couldn't make config dir ${dir}: $!";
}
$self->write_config_entry([ $type => $name ], $value);
}
sub run_named_config_del {
my ($self, $type, $name) = @_;
barf "plx --config ${type} dev <name>" unless $name;
$self->clear_config_entry([ $type => $name ]);
}
sub run_config_libspec_add { shift->run_named_config_add(libspec => @_) }
sub run_config_libspec_del { shift->run_named_config_del(libspec => @_) }
sub show_config_env {
my $max = List::Util::max(
map length, my @names = $self->list_config_names('env')
);
say sprintf("%-${max}s %s", $_, $self->read_config_entry([ env => $_ ]))
for @names;
}
sub run_config_env_add { shift->run_named_config_add(env => @_) }
sub run_config_env_del { shift->run_named_config_del(env => @_) }
sub show_env {
my ($self, $env) = @_;
$self->ensure_layout_config_dir;
local $ENV{$env} = '';
$self->setup_env;
say $_ for split ':', $ENV{$env};
}
sub run_action_libs { $self->show_env('PERL5LIB') }
sub run_action_paths { $self->show_env('PATH') }
sub run_action_env {
$self->ensure_layout_config_dir;
$self->setup_env;
my @env_change;
our %orig_env;
foreach my $key (sort(keys %{{ %orig_env, %ENV }})) {
my ($oval, $eval) = ($orig_env{$key}, $ENV{$key});
if (!defined($eval) or ($oval//'') ne $eval) {
push @env_change, [ $key, $eval ];
}
}
my $shelltype = local::lib->guess_shelltype;
my $shellbuild = "build_${shelltype}_env_declaration";
foreach my $change (@env_change) {
print +local::lib->$shellbuild(@$change);
}
}
sub run_action_help {
require Pod::Usage;
Pod::Usage::pod2usage();
}
sub run_action_version {
say sprintf "%f", $VERSION;
}
sub run_action_base {
my ($self, $base, @chain) = @_;
unless ($base) {
say $self->layout_base_dir;
return;
}
barf "--base <base> <action> <args>" unless @chain;
$self->new({ layout_base_dir => $base })->run(@chain);
}
sub _parse_multi {
my ($self, @args) = @_;
my @multi;
MULTI: while (@args) {
barf "Expected multi arg [, got: $args[0]" unless $args[0] eq '[';
shift @args;
my @action;
while (my $el = shift @args) {
push @multi, \@action and next MULTI if $el eq ']';
push @action, $el;
}
barf "Missing closing ] for multi";
}
return @multi;
}
sub run_action_multi {
my ($self, @args) = @_;
return $self->run_multi(@args) if @args and ref($args[0]);
my @multi = $self->_parse_multi(@args);
$self->run_multi(@multi);
}
sub run_multi {
my ($self, @multi) = @_;
foreach my $multi (@multi) {
my @debug_multi = map +(ref($_) ? ('[', @$_, ']') : $_), @$multi;
stderr '# '.join(' ', plx => @debug_multi);
$self->run(@$multi);
}
}
sub run_action_showmulti {
my ($self, @args) = @_;
my @multi = $self->_parse_multi(@args);
( run in 1.951 second using v1.01-cache-2.11-cpan-437f7b0c052 )