App-PTP
view release on metacpan or search on metacpan
lib/App/PTP/Args.pm view on Meta::CPAN
use 5.022;
use strict;
use warnings;
use App::PTP::Commands ':CMD';
use App::PTP::Util;
use Getopt::Long qw(GetOptionsFromArray :config auto_abbrev no_ignore_case
permute auto_version);
use List::Util;
use Pod::Usage;
use Scalar::Util 'looks_like_number';
our $VERSION = '0.01';
# Name of files or directory to be processed. This can also contain a reference
# to the $stdin_marker variable, to indicate that the standard input needs to be
# processed.
my @inputs;
# The list of actions applied to the input. This is a list of array reference.
# Each of these array will contain the name of the command to run, the coderef
lib/App/PTP/Args.pm view on Meta::CPAN
sub input_flags {
(
'<>' => sub { push @inputs, $_[0] }, # Any options not matched otherwise.
'' => sub { push @inputs, \$App::PTP::Files::stdin_marker }, # a single '-'
)
}
sub is_int {
my ($str) = @_;
return looks_like_number($str) && int($str) == $str;
}
sub validate_cut_spec {
my ($spec) = @_;
my @fields = split /\s*,\s*/, $spec;
for my $f (@fields) {
die "Fields passed to --cut must all be integers: $f\n" unless is_int($f);
$f-- if $f > 0;
}
return \@fields;
lib/App/PTP/Commands.pm view on Meta::CPAN
eval_in_safe_env($code, $options);
if ($@) {
chomp($@);
my $scmd = '-'.($cmd =~ s/^(..)/-$1/r); # --execute or -M.
die "FATAL: Perl code failed in ${scmd}: ${@}\n";
}
}
sub do_load {
my ($content, $markers, $modes, $options, $file) = @_;
# do can open relative paths, but in that case it looks them up in the @INC
# directory, which we want to avoid.
# We don't use abs_path here to not die (just yet) if the file does not exist.
my $abs_path = rel2abs($file);
print "Loading file: '$abs_path'\n" if $options->{debug_mode};
if (not defined eval_in_safe_env("do '${abs_path}';", $options)) {
if ($@) {
die "FATAL: Perl code failed in --load: ${@}\n";
} elsif ($!) {
die "FATAL: Cannot load file '$file' for --load: $!\n";
}
( run in 0.355 second using v1.01-cache-2.11-cpan-64827b87656 )