App-cpangrep
view release on metacpan or search on metacpan
lib/App/cpangrep.pm view on Meta::CPAN
}
}
# Some tricks borrowed from uninames' fork_output()
sub setup_pager {
return unless -t STDOUT;
my $pager = $ENV{PAGER} || 'less';
$ENV{LESS} = 'SRFX' . ($ENV{LESS} || '')
if $pager =~ /less/;
$ENV{LESSCHARSET} = "utf-8"
if $pager =~ /more|less/ and ($ENV{LESSCHARSET} || "") ne "utf-8";
open STDOUT, "| $pager"
or die "couldn't reopen stdout to pager '$pager': $!\n";
# exit cleanly on :q in less
$SIG{PIPE} = sub { exit };
# close piped output, otherwise we screw up terminal
END { close STDOUT or die "error closing stdout: $!\n" }
binmode STDOUT, ':encoding(UTF-8)';
$| = 1;
}
# Setup colored output if we have it
sub setup_colors {
eval { require Term::ANSIColor };
if ( not $@ and supports_color() ) {
$Term::ANSIColor::EACHLINE = "\n";
*color = *_color_real;
*colored = *_colored_real;
}
}
# No-op passthrough defaults
sub color { "" }
sub colored { ref $_[0] ? @_[1..$#_] : $_[0] }
sub _color_real { Term::ANSIColor::color(@_) }
sub _colored_real { Term::ANSIColor::colored(@_) }
sub supports_color {
# We're not on a TTY and don't force it, kill color
return 0 unless -t *STDOUT or $COLOR;
if ( $Config{'osname'} eq 'MSWin32' ) {
eval { require Win32::Console::ANSI; };
return 1 if not $@;
}
else {
return 1 if $ENV{'TERM'} =~ /^(xterm|rxvt|linux|ansi|screen)/;
return 1 if $ENV{'COLORTERM'};
}
return 0;
}
sub debug {
return unless $DEBUG;
warn "DEBUG: ", @_, " [", join("/", (caller(1))[3,2]), "]\n";
}
1;
__END__
=encoding utf-8
=head1 NAME
App::cpangrep - Grep CPAN from the command-line using grep.cpan.me
=head1 SYNOPSIS
cpangrep "\bpackage\s+App::cpangrep\b"
cpangrep --help
=head1 DESCRIPTION
App::cpangrep provides the C<cpangrep> program which is a command-line
interface for L<http://grep.cpan.me>.
=head1 AUTHOR
Thomas Sibley E<lt>tsibley@cpan.orgE<gt>
=head1 COPYRIGHT
Copyright 2013- Thomas Sibley
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
L<cpangrep>, L<http://grep.cpan.me>
=cut
( run in 1.044 second using v1.01-cache-2.11-cpan-5fbc6bb55f2 )