| 1 | package App::BoolFindGrep::Grep; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use common::sense; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use charnames q(:full); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use English qw[-no_match_vars]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Text::Glob qw[glob_to_regex_string]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | our $VERSION = '0.06'; # VERSION | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | has match_expr => ( | ||||||||||||||||||||||||||||
| 14 | is => q(rw), | ||||||||||||||||||||||||||||
| 15 | 17 | ▶ | isa => sub { die if @_ > 1; die if ref $_[0]; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 16 | 5 | default => undef, | |||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | 17 | ▶ | has patterns => ( is => q(rw), default => sub { {}; }, ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 17 | ▶ | has greped => ( is => q(rw), default => sub { {}; }, ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | has fixed_strings => ( | ||||||||||||||||||||||||||||
| 21 | is => q(rw), | ||||||||||||||||||||||||||||
| 22 | 18 | ▶ | isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
Condition66%2/3
$_[0] == 1 or $_[0] == 0
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1
$_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
| |||||||||||||||||||||||||||||
| 23 | 5 | default => 0, | |||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | has ignore_case => ( | ||||||||||||||||||||||||||||
| 26 | is => q(rw), | ||||||||||||||||||||||||||||
| 27 | 18 | ▶ | isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
Condition66%2/3
$_[0] == 1 or $_[0] == 0
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1
$_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
| |||||||||||||||||||||||||||||
| 28 | 5 | default => 0, | |||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | has line_regexp => ( | ||||||||||||||||||||||||||||
| 31 | is => q(rw), | ||||||||||||||||||||||||||||
| 32 | 18 | ▶ | isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
Condition66%2/3
$_[0] == 1 or $_[0] == 0
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1
$_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
| |||||||||||||||||||||||||||||
| 33 | 5 | default => 0, | |||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | has word_regexp => ( | ||||||||||||||||||||||||||||
| 36 | is => q(rw), | ||||||||||||||||||||||||||||
| 37 | 18 | ▶ | isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
Condition66%2/3
$_[0] == 1 or $_[0] == 0
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1
$_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
| |||||||||||||||||||||||||||||
| 38 | 5 | default => 0, | |||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | has glob_regexp => ( | ||||||||||||||||||||||||||||
| 41 | is => q(rw), | ||||||||||||||||||||||||||||
| 42 | 18 | ▶ | isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
Condition66%2/3
$_[0] == 1 or $_[0] == 0
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1
$_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
| |||||||||||||||||||||||||||||
| 43 | 5 | default => 0, | |||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | has content_found => ( | ||||||||||||||||||||||||||||
| 46 | is => q(rw), | ||||||||||||||||||||||||||||
| 47 | 17 | ▶ | default => sub { {}; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 5 | ); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | 0 | my @file = splice @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return unless defined $self->match_expr(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return unless %{ $self->patterns() }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | $self->_process_patterns(); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | while ( my $file = shift @file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | croak sprintf q('%s': nonexistent file.), $file if !-e $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | croak sprintf q('%s': irregular file.), $file if !-f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | croak sprintf q('%s': unreadable file.), $file if !-r $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( my $fh = IO::File->new( $file, q(r) ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | while ( my $line = readline $fh ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | chomp $line; | |||||||||||||||||||||||||||
| 66 | 0 | $self->_search( $line, $file, $fh->input_line_number(), ); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | else { croak $OS_ERROR; } | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | return 1; | |||||||||||||||||||||||||||
| 73 | } ## end sub process | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub _search { | ||||||||||||||||||||||||||
|
Subroutine
_search: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 76 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | 1 | my $string = shift; | |||||||||||||||||||||||||||
| 78 | 1 | my $file = shift; | |||||||||||||||||||||||||||
| 79 | 1 | my $line_number = shift; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | foreach my $pattern ( keys %{ $self->patterns } ) { | |||||||||||||||||||||||||||
| 82 | 6 | my $re = $self->patterns->{$pattern}; | |||||||||||||||||||||||||||
| 83 | 6 | ▶ | $self->greped->{$file}{$pattern} //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->greped->{$file}{$pattern} //= 0
MC/DC0%0/1
$self->greped->{$file}{$pattern} //= 0
$self->greped->{$file}{$pattern}
Truth table50%1/2
A
A= $self->greped->{$file}{$pattern}
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 6 | ▶ | if ( $string =~ m{$re} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 5 | $self->greped->{$file}{$pattern}++; | |||||||||||||||||||||||||||
| 87 | 5 | $self->content_found->{$file}{$line_number} = $string; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | return 1; | |||||||||||||||||||||||||||
| 92 | } ## end sub _search | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 5 | ▶ | sub _process_patterns { | ||||||||||||||||||||||||||
|
Subroutine
_process_patterns: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 95 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 5 | ▶ | die if $self->line_regexp() && $self->word_regexp(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->line_regexp and $self->word_regexp
MC/DC0%0/2
$self->line_regexp and $self->word_regexp
$self->line_regexp
$self->word_regexp
Truth table66%2/3
A and B
A= $self->line_regexpB= $self->word_regexp
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 5 | foreach my $pattern ( keys %{ $self->patterns() } ) { | |||||||||||||||||||||||||||
| 100 | 5 | my $value = $pattern; | |||||||||||||||||||||||||||
| 101 | 5 | ▶ | if ( $self->glob_regexp() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 1 | $value = glob_to_regex_string($value); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | else { | ||||||||||||||||||||||||||||
| 105 | 4 | ▶ | $value = quotemeta $value if $self->fixed_strings(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 4 | ▶ | if ( $self->line_regexp() ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 108 | 1 | $value = sprintf q(\A%s\z), $value; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | elsif ( $self->word_regexp() ) { | ||||||||||||||||||||||||||||
| 111 | 1 | $value = sprintf q(\b%s\b), $value; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 5 | ▶ | $value = $self->ignore_case() ? qr{$value}i : qr{$value}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 5 | $self->patterns->{$pattern} = $value; | |||||||||||||||||||||||||||
| 118 | } ## end foreach my $pattern ( keys ...) | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 5 | return 1; | |||||||||||||||||||||||||||
| 121 | } ## end sub _process_patterns | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 5 | ▶ | no Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 124 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 5 | 1; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||