App-GitGrepPerlStatement

 view release on metacpan or  search on metacpan

bin/git-grep-perl-statement  view on Meta::CPAN

Ordinary C<git-grep '$self'> matches C<$selfie> or C<"$self">. git-grep-perl-statement matches only C<$self>.

Ordinary git-grep shows matched line. git-grep-per-statement shows matched statement.

=head1 EXAMPLES

    % git grep-perl-statement colored
    git-grep-perl-statement:61
    colored($self->highlight_style, $_);
    git-grep-perl-statement:85
    say colored(
        ['bold'],
        "@{[ $file ]}:@{[ $_->line_number ]}"
    );

=head1 LICENSE

Copyright (C) hitode909.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

lib/App/GitGrepPerlStatement.pm  view on Meta::CPAN

package App::GitGrepPerlStatement;
use 5.008001;
use strict;
use warnings;
use App::GitGrepPerlStatement::StatementFinder;
use Term::ANSIColor qw(colored);

our $VERSION = "0.05";

sub say ($) {
    my ($message) = @_;
    print $message . "\n";
}

sub run {
    my ($class, @argv) = @_;

    my $word = (@argv)[0];

    unless (defined $word) {
        say "USAGE: git grep-per-statement <pattern token> <pathspec>";
        exit 1;
    }

    my @files = split "\n", `git grep --name-only --cached --word-regexp @{[ join ' ', map { quotemeta($_) } @argv ]}`;

    my $finder = App::GitGrepPerlStatement::StatementFinder->new($word);

    for my $file (@files) {
        my @found = $finder->search($file);

        for (@found) {
            if (-t STDOUT) {
                say colored(
                    ['bold'],
                    "@{[ $file ]}:@{[ $_->line_number ]}"
                );
                say $finder->highlight($_);
            } else {
                say "@{[ $file ]}:@{[ $_->line_number ]}";
                say $_;
            }
        }
        $finder->flush;
    }

}

__END__

=encoding utf-8



( run in 0.585 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )