App-Timestamper
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/Timestamper.pm view on Meta::CPAN
use App::Timestamper::Filter::TS;
sub new
{
my $class = shift;
my $self = bless {}, $class;
$self->_init(@_);
return $self;
}
sub _init
{
my ( $self, $args ) = @_;
my $argv = [ @{ $args->{argv} } ];
my $help = 0;
my $man = 0;
my $version = 0;
if (
!(
my $ret = GetOptionsFromArray(
$argv,
'help|h' => \$help,
man => \$man,
version => \$version,
)
)
)
{
die "GetOptions failed!";
}
if ($help)
{
pod2usage(1);
}
if ($man)
{
pod2usage( -verbose => 2 );
}
if ($version)
{
print "timestamper version $App::Timestamper::VERSION .\n";
exit(0);
}
$self->{_argv} = $argv;
}
sub run
{
my ($self) = @_;
local @ARGV = @{ $self->{_argv} };
STDOUT->autoflush(1);
App::Timestamper::Filter::TS->new->fh_filter( \*ARGV,
sub { print $_[0]; } );
return;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::Timestamper - prefix lines with the timestamps of their arrivals.
=head1 VERSION
version 0.2.1
=head1 SYNOPSIS
use App::Timestamper;
App::Timestamper->new({ argv => [@ARGV] })->run();
=head1 DESCRIPTION
App::Timestamper is a pure-Perl command line program that filters the input
so the timestamps (in seconds+fractions since the UNIX epoch) are prefixed
to the lines based on the time of the arrival.
So if the input was something like:
First Line
Second Line
Third Line
It will become something like:
1435254285.978485482\tFirst Line
1435254302.569615087\tSecond Line
1435254319.809459781\tThird Line
=head2 Some use cases
Some people asked me what is B<timestamper> useful for, so I'll try to
explain because I wrote the first version out of a need.
Let's suppose you have a simulation that outputs a "Reached $N iterations"
line after every certain number of iterations. Like so:
Reached 100000 iterations
Reached 200000 iterations
Reached 300000 iterations
.
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.652 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )