App-ansicolumn
view release on metacpan or search on metacpan
t/App/cdif/Command.pm view on Meta::CPAN
sub execute {
my $obj = shift;
my $command = shift;
my @command = ref $command eq 'ARRAY' ? @$command : ($command);
use IO::File;
my $pid = (my $fh = IO::File->new)->open('-|') // die "open: $@\n";
if ($pid == 0) {
if (my $stdin = $obj->{STDIN}) {
open STDIN, "<&=", $stdin->fileno or die "open: $!\n";
binmode STDIN, ':encoding(utf8)';
}
open STDERR, ">&STDOUT";
exec @command;
die "exec: $@\n";
}
binmode $fh, ':encoding(utf8)';
do { local $/; <$fh> };
}
sub data {
my $obj = shift;
if (@_) {
$obj->reset->write(shift)->flush->rewind;
$obj;
} else {
$obj->rewind;
t/App/cdif/Command.pm view on Meta::CPAN
my $obj = shift;
$obj->{STDIN};
}
sub setstdin {
my $obj = shift;
my $data = shift;
my $stdin = $obj->{STDIN} //= do {
my $fh = new_tmpfile IO::File or die "new_tmpfile: $!\n";
$fh->fcntl(F_SETFD, 0) or die "fcntl F_SETFD: $!\n";
binmode $fh, ':encoding(utf8)';
$fh;
};
$stdin->seek(0, 0) or die "seek: $!\n";
$stdin->truncate(0) or die "truncate: $!\n";
$stdin->print($data);
$stdin->seek(0, 0) or die "seek: $!\n";
$obj;
}
1;
t/App/cdif/Tmpfile.pm view on Meta::CPAN
use utf8;
use Carp;
use Fcntl;
use IO::File;
use IO::Handle;
sub new {
my $class = shift;
my $fh = new_tmpfile IO::File or die "new_tmpfile: $!\n";
$fh->fcntl(F_SETFD, 0) or die "fcntl F_SETFD: $!\n";
binmode $fh, ':encoding(utf8)';
bless { FH => $fh }, $class;
}
sub write {
my $obj = shift;
my $fh = $obj->fh;
if (@_) {
my $data = join '', @_;
$fh->print($data);
}
( run in 0.612 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )