#!/usr/bin/perl
# $Id: v-method 501 2014-05-14 22:19:48Z whynot $
# Copyright 2014 Eric Pozharski <whynot@pozharski.name>
# GNU GPLv3
# AS-IS, NO-WARRANTY, HOPE-TO-BE-USEFUL

use strict;
use warnings;

package main;
use version 0.77; our $VERSION = version->declare( v0.1.2 );

use IO::Handle;

STDOUT->autoflush( 1 );

my $fn = <DATA>;
chomp $fn;
open STDERR, q|>>|, $fn                        or die qq|[open] (STDERR): $!|;
my $tout = <DATA>;
chomp $tout;
$tout = [ split m{:}, $tout, 2 ];
my $rv = $tout->[1] || 0;
$tout = $tout->[0];

my $self = ( split m{/}, $0 )[-1] . ':';
foreach my $line
( q|100 Capabilities|,
  q|Single-Instance: true|,
  qq|Version: $VERSION|,
  '' ) { print STDERR qq|[$line]\n|; print STDOUT qq|$line\n| }
while( <DATA> )          {
    chomp;
    s{\Q+++\E}{$self}g;
    print STDERR qq|[$_]\n|;
    print STDOUT qq|$_\n| }

my $mark = time;
$SIG{ALRM} = sub { exit $rv };
alarm $tout;
while( <STDIN> )                     {
    chomp;
    print STDERR qq|{$_}\n|;
    time - $mark > $tout and exit $rv }

# vim: set filetype=perl
