App-Greple
view release on metacpan or search on metacpan
script/greple view on Meta::CPAN
=back
Before starting execution, B<greple> reads the file named F<.greplerc>
on user's home directory. Following directives can be used.
=over 7
=item B<option> I<name> string
Argument I<name> of B<option> directive is user defined option name.
The rest are processed by C<shellwords> routine defined in
Text::ParseWords module. Be sure that this module sometimes requires
escape backslashes.
Any kind of string can be used for option name but it is not combined
with other options.
option --fromcode --outside='(?s)\/\*.*?\*\/'
option --fromcomment --inside='(?s)\/\*.*?\*\/'
If the option named B<default> is defined, it will be used as a
default option.
For the purpose to include following arguments within replaced
strings, two special notations can be used in option definition.
String C<$E<lt>nE<gt>> is replaced by the I<n>th argument after the
substituted option, where I<n> is number start from one. String
C<$E<lt>shiftE<gt>> is replaced by following command line argument and
the argument is removed from option list.
For example, when
option --line --le &line=$<shift>
is defined, command
greple --line 10,20-30,40
will be evaluated as this:
greple --le &line=10,20-30,40
=item B<expand> I<name> I<string>
Define local option I<name>. Command B<expand> is almost same as
command B<option> in terms of its function. However, option defined
by this command is expanded in, and only in, the process of
definition, while option definition is expanded when command arguments
are processed.
This is similar to string macro defined by following B<define>
command. But macro expansion is done by simple string replacement, so
you have to use B<expand> to define option composed by multiple
arguments.
=item B<define> I<name> string
Define macro. This is similar to B<option>, but argument is not
processed by I<shellwords> and treated just a simple text, so
meta-characters can be included without escape. Macro expansion is
done for option definition and other macro definition. Macro is not
evaluated in command line option. Use option directive if you want to
use in command line,
define (#kana) \p{InKatakana}
option --kanalist --nocolor -o --join --re '(#kana)+(\n(#kana)+)*'
help --kanalist List up Katakana string
=item B<help> I<name>
If B<help> directive is used for same option name, it will be printed
in usage message. If the help message is C<ignore>, corresponding
line won't show up in the usage.
=item B<builtin> I<spec> I<variable>
Define built-in option which should be processed by option parser.
Arguments are assumed to be L<Getopt::Long> style spec, and
I<variable> is string start with C<$>, C<@> or C<%>. They will be
replaced by a reference to the object which the string represent.
See B<pgp> module for example.
=item B<autoload> I<module> I<options> ...
Define module which should be loaded automatically when specified
option is found in the command arguments.
For example,
autoload -Mdig --dig --git
replaces option "C<--dig>" to "C<-Mdig --dig>", so that B<dig> module
is loaded before processing C<--dig> option.
=back
Environment variable substitution is done for string specified by
C<option> and C<define> directives. Use Perl syntax B<$ENV{NAME}> for
this purpose. You can use this to make a portable module.
When B<greple> found C<__PERL__> line in F<.greplerc> file, the rest
of the file is evaluated as a Perl program. You can define your own
subroutines which can be used by C<--inside>/C<--outside>,
C<--include>/C<--exclude>, C<--block> options.
For those subroutines, file content will be provided by global
variable C<$_>. Expected response from the subroutine is the list of
array references, which is made up by start and end offset pairs.
For example, suppose that the following function is defined in your
F<.greplerc> file. Start and end offset for each pattern match can be
taken as array element C<$-[0]> and C<$+[0]>.
__PERL__
sub odd_line {
my @list;
my $i;
while (/.*\n/g) {
push(@list, [ $-[0], $+[0] ]) if ++$i % 2;
}
( run in 1.370 second using v1.01-cache-2.11-cpan-d8267643d1d )