package Shell::Autobox;
use strict;
use warnings;
use File::Temp;
use Carp qw(confess);
use base qw(autobox);
our $VERSION = '0.03';
sub import {
my $class = shift;
my $caller = (caller)[0];
for my $program (@_) {
my $sub = sub {
my $input = shift;
my $args = join ' ', @_;
my $stdin = File::Temp->new();
my $stdout = File::Temp->new();
my $stderr = File::Temp->new();
my $command = "$program $args $stdin 2> $stderr > $stdout";
my ($output, $error, $status);
print $stdin $input;
$status = system $command;
{
local $/ = undef;
$error = <$stderr>;
$output = <$stdout>;
}
if ($status) {
confess "can't exec $command" . ((length $error) ? ": $error" : '');
} elsif (length $error) {
warn $error;
}
return $output;
};
{
no strict 'refs';
*{"$caller\::$program"} = $sub;
}
}
$class->SUPER::import(SCALAR => $caller);
}
1;
__END__
=head1 NAME
Shell::Autobox - pipe Perl strings through shell commands
=head1 SYNOPSIS
use Shell::Autobox qw(xmllint);
my $xml = '';
my $pretty = $xml->xmllint('--format');
=head1 DESCRIPTION
Shell::Autobox provides an easy way to pipe Perl strings through shell commands. Commands passed as arguments to the
C