App-Greple
view release on metacpan or search on metacpan
lib/App/Greple/Grep.pm view on Meta::CPAN
Returns a list of C<App::Greple::Grep::Match> objects.
=item B<min>, B<max>, B<number>
Shortcuts for C<< $result->block->min >>, etc.
=back
=head1 METHODS
=head2 App::Greple::Grep
=over 4
=item B<result>
Returns a list of C<App::Greple::Grep::Result> objects.
=item B<result_ref>
Returns a reference to the result array. This can be used to modify
the results in a C<--postgrep> function.
=item B<matched>
Returns the total number of matches.
=item B<blocks>
Returns a list of all blocks.
=item B<cut>(I<$from>, I<$to>)
Returns the substring of the text from position I<$from> to I<$to>.
=item B<slice_result>(I<$result>)
Returns a list of strings alternating between unmatched and matched
portions within the block.
=back
=head1 USING --postgrep OPTION
The C<--postgrep> option allows you to process the Grep object after
the search is complete. The function receives the Grep object as its
argument.
sub postgrep {
my $grep = shift;
for my $result ($grep->result) {
for my $match ($result->matched) {
# Modify match attributes
$match->callback = sub { ... };
}
}
}
=head1 CALLBACK EXAMPLE
The L<App::Greple::subst> module uses callbacks to replace matched
text:
my $callback = sub {
my($start, $end, $index, $matched) = @_;
# Return replacement string
return $replacement;
};
for my $match ($result->matched) {
$match->callback = $callback;
}
=head1 SEE ALSO
L<greple>, L<App::Greple::subst>
( run in 2.191 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )