App-Greple
view release on metacpan or search on metacpan
script/greple view on Meta::CPAN
pairs @param;
};
my $file_code;
my $default_icode = 'utf8'; # default input encoding
my @default_icode_list = qw(euc-jp 7bit-jis);
my $output_code;
my $default_ocode = 'utf8'; # default output encoding
$output_code = $opt_ocode || $default_ocode;
binmode STDOUT, ":encoding($output_code)";
## show unused option characters
if ($opt_d{u}) {
my $s = join('','0'..'9',"\n",'a'..'z',"\n",'A'..'Z',"\n");
map { /\|([0-9a-zA-Z])\b/ && $s =~ s/$1/./ } @optargs;
die $s;
}
## show man pages
if ($opt_man or $opt_show or $opt_path) {
script/greple view on Meta::CPAN
open SAVESTDIN, '<&', \*STDIN or die "open: $!";
open SAVESTDOUT, '>&', \*STDOUT or die "open: $!";
open SAVESTDERR, '>&', \*STDERR or die "open: $!";
sub recover_stdin {
open STDIN, '<&', \*SAVESTDIN or die "open: $!";
}
sub recover_stderr {
open STDERR, '>&', \*SAVESTDERR or die "open: $!";
binmode STDERR, ':encoding(utf8)';
}
sub recover_stdout {
close STDOUT;
open STDOUT, '>&', \*SAVESTDOUT or die "open: $!";
}
sub close_stdout {
close SAVESTDOUT;
close STDOUT;
}
script/greple view on Meta::CPAN
if (not defined $content) {
if ($opt_error eq 'fatal') {
die "ABORT on $current_file\n";
}
if ($opt_error ne 'retry') {
warn "SKIP $current_file\n" if $opt_warn{skip};
next FILE;
}
# Try again
binmode STDIN, ':raw';
seek STDIN, 0, 0 or do {
warn "SKIP $current_file (not seekable)\n"
if $opt_warn{skip};
next FILE;
};
$content = $slurp->();
if (not defined $content) {
warn "SKIP* $current_file\n" if $opt_warn{skip};
next FILE;
}
warn "RETRY $current_file\n" if $opt_warn{retry};
$stat{read_retry}++;
binmode STDOUT, ':raw';
}
my $matched = grep_data(\$content);
$stat{match_effective} += $matched;
$stat{file_searched}++;
$stat{length} += length $content;
} continue {
close STDIN; # wait; # wait for 4.019 or earlier?
# recover STDIN for opening '-' and some weird command which needs
# STDIN opened (like unzip)
recover_stdin;
binmode STDOUT, ":encoding($output_code)";
}
}
sub usage {
pod2usage(-verbose => 0, -exitval => "NOEXIT");
my $quote = qr/[\\(){}\|\*?]/;
for my $bucket ($rcloader->buckets) {
my $module = $bucket->module;
print " $module options:\n";
script/greple view on Meta::CPAN
warn "$file: $!\n" unless -l $file;
next;
};
}
if (my @filters = $filter_d->get_filters($file)) {
push_input_filter({ &FILELABEL => $file }, @filters);
}
if ($file_code eq 'binary') {
binmode STDIN, ":raw";
} else {
binmode STDIN, ":encoding($file_code)";
}
return $file;
}
undef;
}
######################################################################
sub grep_data {
t/runner/Runner.pm view on Meta::CPAN
use IO::File;
sub run {
my $obj = shift;
use IO::File;
my $pid = (my $fh = new IO::File)->open('-|') // die "open: $@\n";
if ($pid == 0) {
if (my $stdin = $obj->{STDIN}) {
open STDIN, "<&=", $stdin->fileno or die "open: $!\n";
$stdin->fcntl(F_SETFD, 0) or die "fcntl F_SETFD: $!\n";
binmode STDIN, ':encoding(utf8)';
}
open STDERR, ">&STDOUT";
$obj->execute;
exit 1;
}
$obj->{STDIN} = undef;
binmode $fh, ':encoding(utf8)';
$obj->{stdout} = do { local $/; <$fh> };
my $child = wait;
$child != $pid and die "child = $child, pid = $pid";
$obj->{pid} = $pid;
$obj->{result} = $?;
$obj;
}
sub status {
my $obj = shift;
t/runner/Runner.pm view on Meta::CPAN
}
*result = \&stdout; # for backward compatibility
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;
}
##
( run in 1.886 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )