App-Greple
view release on metacpan or search on metacpan
lib/App/Greple/Filter.pm view on Meta::CPAN
sub push_output_filter {
my %arg = ref $_[0] eq 'HASH' ? %{+shift} : ();
my $fh = shift;
my $pkg = caller;
for my $filter (reverse @_) {
$debug{F} and warn "Push output Filter: \"$filter\"\n";
my $pid = open($fh, '|-') // die "$filter: $!\n";
if ($pid == 0) {
if ($filter =~ /^&/ and
my $f = parse_func({ PACKAGE => $pkg }, $filter)) {
local @ARGV;
open STDIN, '<&', 0 if eof STDIN;
$f->call;
} else {
do { exec $filter } ;
warn $@ if $@;
}
STDOUT->flush();
STDERR->flush();
POSIX::_exit(0);
}
t/19_filter_option.t view on Meta::CPAN
use warnings;
use utf8;
use Test::More;
use File::Spec;
use open IO => ':utf8', ':std';
use lib '.';
use t::Util;
my $sample = 't/SAMPLE.txt';
my $content = do { local @ARGV = $sample; local $/; <> };
# --filter without pattern: output entire file
is(run("--filter --color=never $sample")->stdout,
$content, "--filter without pattern");
# -F short option
is(run("-F --color=never $sample")->stdout,
$content, "-F short option");
# --filter with matching pattern: output entire file with highlights
( run in 1.201 second using v1.01-cache-2.11-cpan-99c4e6809bf )