| 1 | package File::CodeSearch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Created on: 2009-08-07 18:32:44 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use File::chdir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use File::TypeCategories; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Clone qw/clone/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | our $VERSION = version->new('0.7.5'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | has regex => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | isa => 'File::CodeSearch::RegexBuilder', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | has files => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | isa => 'File::TypeCategories', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | default => sub { File::TypeCategories->new }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | has recurse => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | has breadth => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | has depth => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | has quiet => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | has suround_before => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | has suround_after => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | has limit => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | has links => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | default => sub{{}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | has found => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | writer => '_found', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | sub search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | my ($self, $search, @dirs) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | for my $dir (@dirs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 5 | $self->_find($search, $dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | sub _find { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 11 | ▶ | my ($self, $search, $dir, $parent) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find: called CC=20 SCAR=35.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | my @files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 11 | $dir =~ s{/$}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # check if we have a directory and we can change into it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | ▶ | return if !-d $dir || !-r $dir || !-x $dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
-d $dir and -r $dir and -x $dir
-d $dir and -r $dir
MC/DC33%1/3
-d $dir and -r $dir and -x $dir
-d $dir
-r $dir
-x $dir
Truth table50%2/4
A and B and C
A= -d $dirB= -r $dirC= -x $dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 10 | local $CWD = $dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 10 | opendir my $dirh, '.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 10 | ▶ | @files = sort _alpha_num grep { $_ ne '.' && $_ ne '..' } readdir $dirh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 10 | ▶ | if ($self->breadth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | @files = sort _breadth @files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | elsif ($self->depth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | @files = sort _depth @files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 10 | ▶ | $dir = $dir eq '.' ? '' : "$dir/"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | FILE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 10 | for my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 30 | ▶ | next FILE if !$self->files->file_ok("$dir$file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 30 | ▶ | last FILE if $self->limit && $self->found >= $self->limit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->limit and $self->found >= $self->limit
MC/DC0%0/2
$self->limit and $self->found >= $self->limit
$self->limit
$self->found >= $self->limit
Truth table33%1/3
A and B
A= $self->limitB= $self->found >= $self->limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 30 | ▶ | if (-l "$dir$file") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | next FILE if !$self->files->symlinks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $real = path("$dir$file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $real = $real->realpath; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $self->links->{$real} ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->links->{$real} ||= 0
MC/DC0%0/1
$self->links->{$real} ||= 0
$self->links->{$real}
Truth table0%0/2
A
A= $self->links->{$real}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | next FILE if $self->links->{$real}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 30 | ▶ | if (-d "$dir$file") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | ▶ | if ($self->recurse) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 6 | ▶ | $self->_find( $search, "$dir$file", $parent || $dir ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$parent || $dir
MC/DC0%0/2
$parent || $dir
$parent
$dir
Truth table66%2/3
A || B
A= $parentB= $dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 24 | ▶ | $self->search_file( $search, "$dir$file", $parent || $dir ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$parent || $dir
MC/DC0%0/2
$parent || $dir
$parent
$dir
Truth table66%2/3
A || B
A= $parentB= $dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 10 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | sub _alpha_num { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 36 | ▶ | my $a1 = $a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alpha_num: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 36 | my $b1 = $b; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 36 | $a1 =~ s/(\d+)/sprintf "%5d", $1/exms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 36 | $b1 =~ s/(\d+)/sprintf "%5d", $1/exms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 36 | return $a1 cmp $b1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | sub _breadth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | ▶ | -f $a && -d $b ? 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_breadth: called CC=5 SCAR=17.1
Branch: 2 branches
Condition66%4/6
-f $a and -d $b
-d $a and -f $b
MC/DC0%0/2
-f $a and -d $b
-f $a
-d $b
MC/DC50%1/2
-d $a and -f $b
-d $a
-f $b
Truth table66%2/3
A and B
A= -f $aB= -d $b
Truth table66%2/3
A and B
A= -d $aB= -f $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | : -d $a && -f $b ? -1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | sub _depth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | ▶ | -f $a && -d $b ? -1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_depth: called CC=5 SCAR=17.1
Branch: 2 branches
Condition66%4/6
-f $a and -d $b
-d $a and -f $b
MC/DC0%0/2
-f $a and -d $b
-f $a
-d $b
MC/DC50%1/2
-d $a and -f $b
-d $a
-f $b
Truth table66%2/3
A and B
A= -f $aB= -d $b
Truth table66%2/3
A and B
A= -d $aB= -f $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | : -d $a && -f $b ? 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | sub search_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 24 | ▶ | my ($self, $search, $file, $parent) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search_file: called CC=28 SCAR=41.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 24 | ▶ | open my $fh, '<', $file or $self->_message(file => $file, $OS_ERROR) and return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
&File::CodeSearch::open(my $fh, '<', $file) || $self->_message('file', $file, $File::CodeSearch::OS_ERROR) && (return)
$self->_message("file", $file, $File::CodeSearch::OS_ERROR) and return
MC/DC0%0/2
&File::CodeSearch::open(my $fh, '<', $file) || $self->_message('file', $file, $File::CodeSearch::OS_ERROR) && (return)
&File::CodeSearch::open(my $fh, '<', $file)
$self->_message("file", $file, $File::CodeSearch::OS_ERROR)
Truth table33%1/3
A || B
A= &File::CodeSearch::open(my $fh, '<', $file)B= $self->_message("file", $file, $File::CodeSearch::OS_ERROR)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 24 | $self->regex->reset_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 24 | $self->regex->current_file($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 24 | my $before_max = $self->suround_before; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 24 | my $after_max = $self->suround_after; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 24 | my @before; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | my @after; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 24 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 24 | my $found = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 24 | my %args = ( codesearch => $self, before => \@before, after => \@after, lines => \@lines, parent => $parent ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 24 | my @sub_matches; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | my $post; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | LINE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 24 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 4508 | ▶ | if ( $self->regex->isa('File::CodeSearch::Replacer') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 4508 | ▶ | if (!defined $found) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1219 | push @before, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1219 | ▶ | shift @before if @before > $before_max + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | elsif ($found) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 3289 | push @after, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 3289 | ▶ | if (@after > $after_max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 3289 | undef $found; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 4508 | ▶ | last LINE if @{$self->regex->sub_not_matches} && $self->regex->sub_not_match; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@{$self->regex->sub_not_matches;} and $self->regex->sub_not_match
MC/DC0%0/2
@{$self->regex->sub_not_matches;} and $self->regex->sub_not_match
@{$self->regex->sub_not_matches;}
$self->regex->sub_not_match
Truth table33%1/3
A and B
A= @{$self->regex->sub_not_matches;}B= $self->regex->sub_not_match
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 4508 | ▶ | next LINE if !$self->regex->match($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 3312 | pop @before; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3312 | ▶ | pop @after if $args{last_line_no} && $fh->input_line_number - $args{last_line_no} > $after_max - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"last_line_no"} and $fh->input_line_number - $args{"last_line_no"} > $after_max - 1
MC/DC50%1/2
$args{"last_line_no"} and $fh->input_line_number - $args{"last_line_no"} > $after_max - 1
$args{"last_line_no"}
$fh->input_line_number - $args{"last_line_no"} > $after_max - 1
Truth table66%2/3
A and B
A= $args{"last_line_no"}B= $fh->input_line_number - $args{"last_line_no"} > $after_max - 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 3312 | ▶ | if (@{$self->regex->sub_matches}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | push @sub_matches, clone [ $line, $file, $fh->input_line_number, %args ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 3312 | $self->_found( $self->found + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 3312 | $post = $search->($line, $file, $fh->input_line_number, %args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 3312 | ▶ | last LINE if $self->limit && $self->found >= $self->limit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->limit and $self->found >= $self->limit
MC/DC0%0/2
$self->limit and $self->found >= $self->limit
$self->limit
$self->found >= $self->limit
Truth table33%1/3
A and B
A= $self->limitB= $self->found >= $self->limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 3312 | $args{last_line_no} = $fh->input_line_number; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 3312 | @after = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 3312 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 24 | ▶ | if ( @{$self->regex->sub_matches} && $self->regex->sub_match ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@{$self->regex->sub_matches;} and $self->regex->sub_match
MC/DC0%0/2
@{$self->regex->sub_matches;} and $self->regex->sub_match
@{$self->regex->sub_matches;}
$self->regex->sub_match
Truth table33%1/3
A and B
A= @{$self->regex->sub_matches;}B= $self->regex->sub_match
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | SUB: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | for my $args (@sub_matches) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $self->_found( $self->found + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $post = $search->( @$args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | last SUB if $self->limit && $self->found >= $self->limit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->limit and $self->found >= $self->limit
MC/DC0%0/2
$self->limit and $self->found >= $self->limit
$self->limit
$self->found >= $self->limit
Truth table0%0/3
A and B
A= $self->limitB= $self->found >= $self->limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # check if the line is an after match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 24 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$post or @after and !@{$self->regex->sub_matches;} || $self->regex->sub_match
@after and !@{$self->regex->sub_matches;} || $self->regex->sub_match
not @{$self->regex->sub_matches;} or $self->regex->sub_match
MC/DC0%0/4
$post or @after and !@{$self->regex->sub_matches;} || $self->regex->sub_match
$post
@after
not @{$self->regex->sub_matches;}
$self->regex->sub_match
Truth table20%1/5
A or B and not(C) or D
A= $postB= @afterC= not @{$self->regex->sub_matches;}D= $self->regex->sub_match
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | $post | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | || ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | @after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ! @{$self->regex->sub_matches} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | || $self->regex->sub_match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 11 | ▶ | pop @after if $args{last_line_no} && $fh->input_line_number - $args{last_line_no} > $after_max - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"last_line_no"} and $fh->input_line_number - $args{"last_line_no"} > $after_max - 1
MC/DC0%0/2
$args{"last_line_no"} and $fh->input_line_number - $args{"last_line_no"} > $after_max - 1
$args{"last_line_no"}
$fh->input_line_number - $args{"last_line_no"} > $after_max - 1
Truth table33%1/3
A and B
A= $args{"last_line_no"}B= $fh->input_line_number - $args{"last_line_no"} > $after_max - 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 11 | @before = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 11 | $self->_found( $self->found + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 11 | $search->(undef, $file, $fh->input_line_number, %args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 24 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | sub _message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | ▶ | my ($self, $type, $name, $error) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_message: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | if ( !$self->quiet ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | warn "Could not open the $type '$name': $error\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | File::CodeSearch - Search file contents in code repositories | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | This documentation refers to File::CodeSearch version 0.7.5. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | use File::CodeSearch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # Simple usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | code_search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | my ($file, $line) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # do stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | @dirs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # More control | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | my $cs = File::CodeSearch->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | $cs->code_search(sub {}, @dirs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | =head2 C<new ( %params )> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | B<Parameters>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | =item C<regex> - L<File::CodeSearch::RegexBuilder> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | This is the object that handles the testing of individual lines in a file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | and must be created with the search options desired, note you can also use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | the C<F::C::Highlighter> and C<F::C::Replacer> modules interchangeably with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | C<F::C::RegexBuilder>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | =item C<files> - L<File::TypeCategories> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | If you desire to limit files by file type, name, symlink status pass this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | object, other wise a default object will be created. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | =item C<recurse> - Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | Set to false to not recurse into sub directories. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | =item C<breadth> - Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | Changes the search order to breadth first i.e. the searching will search all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | the ordinary files in a directory before searching the directories. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | default is to search directories when they are found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | =item C<depth> - Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | Changes the search order to depth first i.e. the searching will search all the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | sub directories in a directory before searching the ordinary files. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | default is to search directories when they are found. If both C<breadth> and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | C<depth> are both true C<breadth> will be used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | =item C<suround_before> - Int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | Specifies the maximum number of lines before a match is found that should be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | passed to the searching code reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | =item C<suround_after> - Int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | Specifies the maximum number of lines after a match is found that should be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | passed to the searching code reference. B<Note> the after match lines are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | passed to the next matched line in a file or to a call at the end of a file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | with matches. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | =item C<limit> - Int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | Stops matching after C<limit> matches have been found across all files that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | have been searched. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | B<Return>: C<File::CodeSearch> - new object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | B<Description>: Creates & configure a C<File::CodeSearch> object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | =head2 C<search ( $search, @dirs )> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | B<Arguments>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | =item C<$search> - code ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | Subroutine to be executed each time a match in a file is found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | The subroutine should have accept parameters as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | $search->($line, $file, $line_number, %named); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | =item C<$line> - string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | The line from the file that was matched by C<regex>. If searching with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | C<after> set this may be undefined when called with the lines found after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | the last match at the end of the file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | =item C<$file> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | The file name that the line was found in (relative to the supplied directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | =item C<$line_number> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | The line number in the said file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | =item C<%named> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | This contains all the other helpful values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | =item C<codesearch> - C<F::CodeSearch> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | The object that is doing the searching. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | =item C<before> - ArrayRef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | An array of lines that were found before the matched line. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | =item C<after> - ArrayRef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | An array of lines that were found after the last matched line. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | =item C<lines> - ArrayRef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | An array of lines of the file. This is only present if C<regex> is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | C<F::C::Replacer> object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | =item C<parent> - path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | The parent path from @path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | =item C<@dir> - paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | An array of the directory paths to search through. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | B<Return>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | B<Description>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | =head2 C<search_file ( $search, $file, $parent )> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | B<Param>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | =item C<$search> - CodeRef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | See C<search> above for details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | =item C<$file> - file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | A file to search through line by line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | =item C<$parent> - path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | The directory from @dirs which the file was found in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | B<Description>: Searches an individual file for matches. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | =head1 DIAGNOSTICS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | =head1 INCOMPATIBILITIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | There are no known bugs in this module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | Please report problems to Ivan Wills (ivan.wills@gmail.com). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | Patches are welcome. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | Ivan Wills - (ivan.wills@gmail.com) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | Copyright (c) 2009-2011 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | This module is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | the same terms as Perl itself. See L<perlartistic>. This program is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||