App-after
view release on metacpan or search on metacpan
$toc_line =~ /\S/ or last;
$toc_line =~ /^([^,]+),(\d+),(\d+)(?:,(.*))?$/
or die "Invalid TOC line #$i in data section: $toc_line";
$toc{$1} = [$2, $3, $4];
}
my $pos = tell $fh;
$toc{$_}[0] += $pos for keys %toc;
# calculate the line number of data section
my $data_pos = tell(DATA);
seek DATA, 0, 0;
my $pos = 0;
while (1) {
my $line = <DATA>;
$pos += length($line);
$data_linepos++;
last if $pos >= $data_pos;
}
seek DATA, $data_pos, 0;
\%toc;
};
if ($toc->{$_[1]}) {
seek DATA, $toc->{$_[1]}[0], 0;
read DATA, my($content), $toc->{$_[1]}[1];
my ($order, $lineoffset) = split(';', $toc->{$_[1]}[2]);
$content =~ s/^#//gm;
$content = "# line ".($data_linepos + $order+1 + $lineoffset)." \"".__FILE__."\"\n" . $content;
open my $fh, '<', \$content
or die "DataPacker error loading $_[1]: $!";
return $fh;
}
return;
};
}
# END DATAPACK CODE
package main;
use 5.010001;
use strict;
#use warnings;
require Scalar::Util::Numeric::PP;
require Time::Duration::Parse::AsHash;
### declare global variables
my $_pci_r = {naked_res=>0};
my %_pci_args;
### declare subroutines
sub _pci_err {
my $res = shift;
print STDERR "ERROR $res->[0]: $res->[1]\n";
exit $res->[0]-300;
}
sub _pci_json {
state $json = do {
if (eval { require JSON::XS; 1 }) { JSON::XS->new->canonical(1)->allow_nonref }
elsif (eval { require JSON::PP; 1 }) { JSON::PP->new->canonical(1)->allow_nonref }
else { require JSON::Tiny::Subclassable; JSON::Tiny::Subclassable->new }
};
$json;
}
### parse cmdline options
{
require Getopt::Long::EvenLess;
my %mentioned_args;
my $go_spec = {
'all' => sub {
$_pci_args{'all'} = $_[1];
},
'command-json=s' => sub {
$_pci_args{'command'} = _pci_json()->decode($_[1]);
},
'command=s@' => sub {
if ($mentioned_args{'command'}++) { push @{ $_pci_args{'command'} }, $_[1] } else { $_pci_args{'command'} = [$_[1]] }
},
'd=s' => sub {
$_pci_args{'delay'} = $_[1];
},
'delay=s' => sub {
$_pci_args{'delay'} = $_[1];
},
'format=s' => sub {
$_pci_r->{format} = $_[1];
},
'help|h|?' => sub {
print "after - Run command after delay and/or other conditions\n\nUsage:\n after --help (or -h, -?)\n after --version (or -v)\n after [options] <command>...\n\nExamples:\n Run command after 30-minute delay:\n % after --delay 30m cmd\n\n ...
},
'json' => sub {
$_pci_r->{format} = (-t STDOUT) ? "json-pretty" : "json";
},
'load-above=f' => sub {
$_pci_args{'load_above'} = $_[1];
},
'load-below=f' => sub {
$_pci_args{'load_below'} = $_[1];
},
'naked-res' => sub {
$_pci_r->{naked_res} = 1;
},
'no-all' => sub {
$_pci_args{'all'} = $_[1];
},
'no-naked-res|nonaked-res' => sub {
$_pci_r->{naked_res} = 0;
},
'no-none' => sub {
$_pci_args{'none'} = $_[1];
},
'no-or' => sub {
$_pci_args{'or'} = $_[1];
},
'noall' => sub {
$_pci_args{'all'} = $_[1];
},
# elsif ($ref eq 'HASH') { $process_hash->($e) }
# elsif ($ref) { $e = $ref; $ref = "" }
#} } }
#if (!$process_hash) { $process_hash = sub { my $h = shift; for my $k (keys %$h) { my $ref=ref($h->{$k});
# if ($ref eq 'DateTime') { $h->{$k} = $h->{$k}->epoch; $ref = ref($h->{$k}) }
# elsif ($ref eq 'Regexp') { $h->{$k} = "$h->{$k}" }
# elsif ($ref eq 'SCALAR') { $h->{$k} = ${ $h->{$k} }; $ref = ref($h->{$k}) }
# elsif ($ref eq 'Time::Moment') { $h->{$k} = $h->{$k}->epoch; $ref = ref($h->{$k}) }
# elsif ($ref eq 'version') { $h->{$k} = "$h->{$k}" }
# elsif (Scalar::Util::blessed($h->{$k})) { if (!$Data::Clean::_clone && 0) { $h->{$k} = Acme::Damn::damn($h->{$k}) } else { $h->{$k} = Function::Fallback::CoreOrPP::_unbless_fallback($h->{$k}) } $ref = ref($h->{$k}) }
# elsif ($ref && $refs{ $h->{$k} }++) { if (++$ctr_circ <= 1) { $h->{$k} = Data::Clone::clone($h->{$k}); redo } else { $h->{$k} = 'CIRCULAR' } $ref = ref($h->{$k}) }
# elsif ($ref eq 'ARRAY') { $process_array->($h->{$k}) }
# elsif ($ref eq 'HASH') { $process_hash->($h->{$k}) }
# elsif ($ref) { $h->{$k} = $ref; $ref = "" }
#} } }
#%refs = (); $ctr_circ=0;
#for ($data) { my $ref=ref($_);
# if ($ref eq 'DateTime') { $_ = $_->epoch; $ref = ref($_) }
# elsif ($ref eq 'Regexp') { $_ = "$_" }
# elsif ($ref eq 'SCALAR') { $_ = ${ $_ }; $ref = ref($_) }
# elsif ($ref eq 'Time::Moment') { $_ = $_->epoch; $ref = ref($_) }
# elsif ($ref eq 'version') { $_ = "$_" }
# elsif (Scalar::Util::blessed($_)) { if (!$Data::Clean::_clone && 0) { $_ = Acme::Damn::damn($_) } else { $_ = Function::Fallback::CoreOrPP::_unbless_fallback($_) } $ref = ref($_) }
# elsif ($ref && $refs{ $_ }++) { if (++$ctr_circ <= 1) { $_ = Data::Clone::clone($_); redo } else { $_ = 'CIRCULAR' } $ref = ref($_) }
# elsif ($ref eq 'ARRAY') { $process_array->($_) }
# elsif ($ref eq 'HASH') { $process_hash->($_) }
# elsif ($ref) { $_ = $ref; $ref = "" }
#}
#$data
#}
#;; $cleanser->(shift) }
#1;
### Perinci/Result/Format/Lite.pm ###
#package Perinci::Result::Format::Lite;
#
#our $DATE = '2016-04-08';
#our $VERSION = '0.14';
#
#use 5.010001;
#use strict;
#use warnings;
#
#use List::Util qw(first);
#
#require Exporter;
#our @ISA = qw(Exporter);
#our @EXPORT_OK = qw(format);
#
#sub firstidx (&@) {
# my $f = shift;
# foreach my $i ( 0 .. $#_ )
# {
# local *_ = \$_[$i];
# return $i if $f->();
# }
# return -1;
#}
#
#sub _json {
# state $json = do {
# if (eval { require Cpanel::JSON::XS; 1 }) { Cpanel::JSON::XS->new->canonical(1)->convert_blessed->allow_nonref }
# elsif (eval { require JSON::Tiny::Subclassable; 1 }) { JSON::Tiny::Subclassable->new }
# elsif (eval { require JSON::PP; 1 }) { JSON::PP->new->canonical(1)->convert_blessed->allow_nonref }
# else { die "Can't find any JSON module" }
# };
# $json;
#};
#
#sub __cleanse {
# state $cleanser = do {
# eval { require Data::Clean::JSON; 1 };
# if ($@) {
# undef;
# } else {
# Data::Clean::JSON->get_cleanser;
# }
# };
# if ($cleanser) {
# $cleanser->clean_in_place($_[0]);
# } else {
# $_[0];
# }
#}
#
#sub __gen_table {
# my ($data, $header_row, $resmeta, $format) = @_;
#
# $resmeta //= {};
#
# my @columns;
# if ($header_row) {
# @columns = @{$data->[0]};
# } else {
# @columns = map {"col$_"} 0..@{$data->[0]}-1;
# }
#
# my $column_orders;
# SET_COLUMN_ORDERS: {
#
# my $tcos;
# if ($ENV{FORMAT_PRETTY_TABLE_COLUMN_ORDERS}) {
# $tcos = _json->encode($ENV{FORMAT_PRETTY_TABLE_COLUMN_ORDERS});
# } elsif (my $rfos = ($resmeta->{'cmdline.format_options'} //
# $resmeta->{format_options})) {
# my $rfo = $rfos->{'text-pretty'} // $rfos->{text} // $rfos->{any};
# if ($rfo) {
# $tcos = $rfo->{table_column_orders};
# }
# }
# if ($tcos) {
# COLS:
# for my $cols (@$tcos) {
# for my $col (@$cols) {
# next COLS unless first {$_ eq $col} @columns;
# }
# $column_orders = $cols;
# last SET_COLUMN_ORDERS;
# }
# }
#
# $column_orders = $resmeta->{'table.fields'};
( run in 1.124 second using v1.01-cache-2.11-cpan-6aa56a78535 )