#!/usr/bin/env perl
my ($channel, $exit, @stuff) = @ARGV;
my $fh = $channel eq 'stderr' ? \*STDERR : \*STDOUT;
if (@stuff) {
   if ($stuff[0] eq '-') {
      my $everything = do { local $/; <STDIN> };
      print {$fh} $everything;
   }
   else {
      print {$fh} "@stuff";
   }
}
kill -$exit, $$ if ($exit < 0);
exit $exit;
__END__

=pod

=encoding utf8

=head1 SYNOPSIS

   # just like true: no output, exit code 0
   sparring stdout 0 

   # a simple echo
   sparring stdout 0 hello world

   # something on stderr
   sparring stderr 0 hello world

   # print something, then exit code 42
   sparring stdout 42 something

   # print something, then self-kill with signal 10
   sparring stdout -10 something

=cut
