blib/lib/File/Searcher.pm

filter: Statementstmt 86.6% 240 / 277 Branchbran 63.7% 79 / 124 Conditioncond 56.9% 33 / 58 MC/DCmcdc 42.4% 14 / 33 Subroutinesub 87.1% 27 / 31 Podpod 0.0% 0 / 6 totaltotal 74.2% 393 / 529 CC 88 SCAR 29.7
CC
88
Cov
77%
_find_file
36.2
_process_file
34.0
_get_search
21.3
CRAP 19.5
↑ Summary
1 package File::Searcher;
2  
3 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Flock;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Class::Struct;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Class::Generate qw(class subclass);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use vars qw($VERSION $DEBUG $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 $VERSION = '0.92';
13 1 $DEBUG=0;
14  
15  
16 1 struct Stats => {device_code=>'$', inode_number=>'$', mode_flags=>'$', link_cnt=>'$', user_id=>'$', group_id=>'$', device_type=>'$', size_bytes=>'$', time_access_seconds=>'$', time_modified_seconds=>'$', time_status_seconds=>'$', block_system=>'$', block_file=>'$', time_access_string=>'$', time_modified_string=>'$', time_status_string=>'$', mode_string=>'$',};
17 1 struct Properties => {readable_e=>'$', writable_e=>'$', executable_e=>'$', readable_r=>'$', writable_r=>'$', executable_r=>'$', owned_e=>'$', owned_r=>'$', exist=>'$', exist_non_zero=>'$', zero_size=>'$', file=>'$', directory=>'$', link_=>'$', pipe_=>'$', socket_=>'$', block=>'$', character=>'$', setuid_bit=>'$', setgid_bit=>'$', sticky_bit=>'$', opened_tty=>'$', text=>'$', binary=>'$', stats=>'Stats', path=>'$', dir=>'$', name=>'$',};
18 1 struct Match => {match=>'$',pre=>'$',post=>'$',last=>'$',start_offset=>'$',end_offset=>'$',contents=>'$',};
19 1 class Expression=>{
20 search=>{type=>'$', required=>1, default=>'""'},
21 replace=>{type=>'$', required=>1, default=>'""'},
22 options=>{type=>'$', required=>1, default=>'""'},
23 eval_replacement=>{type=>'$', required=>0},
24 case_insensitive=>{type=>'$', required=>0},
25 multiline=>{type=>'$', required=>0},
26 singleline=>{type=>'$', required=>0},
27 repeat=>{type=>'$', required=>0},
28 extend=>{type=>'$', required=>0},
29 do_all=>{type=>'$', default=>'0'},
30 skip_expression=>{type=>'$', default=>'0'},
31 files_matched=>{type=>'@'},
32 files_replaced=>{type=>'@'},
33 replacements=>{type=>'%'},
34 matches=>{type=>'%'},
35 };
36 1 class Search=>{
37 start_directory=>{type=>'$',default=>"'./'"},
38 backup_extension=>{type=>'$',default=>"'.bak'"},
39 do_backup=>{type=>'$', default=>'0'},
40 recurse_subs=>{type=>'$', default=>'1'},
41 do_replace=>{type=>'$', default=>'0'},
42 log_mode=>{type=>'$', default=>'111'},
43 do_archive=>{type=>'$', default=>'0'},
44 archive=>{type=>'$'},
45 # expression
46 expression=>{type=>'%Expression'},
47 # constructor
48 file_expression=>{type=>'$'},
49 files=>{type=>'@'},
50 # reports
51 files_matched=>{type=>'@'},
52 file_cnt=>{type=>'$', default=>'0'},
53 file_text_cnt=>{type=>'$', default=>'0'},
54 file_binary_cnt=>{type=>'$', default=>'0'},
55 file_unknown_cnt=>{type=>'$', default=>'0'},
56 unknown_cnt=>{type=>'$', default=>'0'},
57 link_cnt=>{type=>'$', default=>'0'},
58 dir_cnt=>{type=>'$', default=>'0'},
59 socket_cnt=>{type=>'$', default=>'0'},
60 pipe_cnt=>{type=>'$', default=>'0'},
61 };
62  
63  
64 7 ▶sub new{
Subroutine new: called CC=9 SCAR=23.7
Pod undocumented
65  
66 7 my $class = shift;
67 7 my $self = {};
68 7 bless $self, $class;
69  
70 # new(\@files); explicit file list (array ref context)
71 # new('*.html'); file match expression (scalar context)
72 # new(var=>val,var=>val); search variables (list context)
73 # new(\@files, {var=>val,var=>val});
74 # new('*.html', {var=>val,var=>val});
75 7 my($files);
76 7 my $file_expression = '';
77 7 ▶ if(ref $_[1] eq 'HASH')
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[1] eq 'HASH') { } 0 7 7
elsif (ref $_[0] eq 'ARRAY') { } 4 3 7
elsif (scalar @_ == 1) { } 2 1 3
78 {
79 # new(\@files, {var=>val,var=>val});
80 0 ▶ if(ref $_[0] eq 'ARRAY'){($files) = shift;}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
81 # new('*.html', {var=>val,var=>val});
82 0 else{($file_expression)=shift;}
83 0 my ($options) = shift;
84 0 foreach (keys %{$options}){push(@_, $_); push(@_, $options->{$_});}
85 }
86 4 elsif(ref $_[0] eq 'ARRAY'){$files = shift;} # new(\@files);
87 2 elsif(scalar(@_) == 1){$file_expression = shift;} # new('*.html');
88 7 $self->{_search} = Search->new(@_); # @_ will be nothing || list of options
89 7 ▶ $file_expression = $file_expression || $self->file_expression;
Condition100%3/3
$file_expression || $self->file_expression
l!l&&r!l&&!r
214
MC/DC100%2/2
$file_expression || $self->file_expression
$file_expression $self->file_expression
Truth table100%3/3
A || B
A= $file_expressionB= $self->file_expression
ABresult
1X1
011
000
90 7 $file_expression =~ s/([^\\])\./$1\\./g;
91 7 $file_expression =~ s/^\*/.*/;
92 7 $file_expression =~ s/\.\./\./g;
93 7 $self->file_expression($file_expression);
94 7 ▶ $self->files(\@{$files}) unless $self->files > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->files > 0 7 0 7
95 7 ▶ $self->start_directory($self->_get_cwd()) if $self->start_directory eq './';
Branch: 1 branch
BranchTrueFalseTotal
if $self->start_directory eq "./" 7 0 7
96 7 ▶ $self->{_on_file_match} = sub {return 1;};
Subroutine __ANON__: called CC=1 SCAR=0.0
97 7 ▶ $self->{_on_expression_match} = sub {return 1;};
Subroutine __ANON__: called CC=1 SCAR=0.0
98 7 $self->{_interactive} = 0;
99 7 $self->{_expressions} = [];
100  
101 7 return $self;
102 }
103  
104 5 ▶sub add_expression{
Subroutine add_expression: called CC=4 SCAR=13.9
Pod undocumented
105 5 my $self = shift;
106 5 my (@options) = @_;
107 5 my @args = ();
108 5 my $expression_name;
109  
110 5 ▶ while(@options)
Branch: 1 branch
BranchTrueFalseTotal
if (@options) 20 5 25
111 {
112 20 my $name = shift @options;
113 20 my $val = shift @options;
114 20 ▶ if($name =~ /name/i){$expression_name = $val;}
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /name/i) { } 5 15 20
115 15 else{push(@args, $name); push(@args, $val);}
116 }
117 5 my $expression = Expression->new(@args);
118 5 ▶ push(@{$self->{_expressions}}, $expression_name) unless $self->{_search}->expression($expression_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_search"}->expression($expression_name) 5 0 5
119 5 $self->{_search}->expression($expression_name, $expression);
120  
121 }
122  
123 0 ▶sub on_file_match{
Subroutine on_file_match: not called CC=2 SCAR=17.9
Pod undocumented
124 0 my $self = shift;
125 0 my ($sub_ref) = @_;
126 0 ▶ $self->{_on_file_match} = $sub_ref if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
127 }
128  
129 0 ▶sub on_expression_match{
Subroutine on_expression_match: not called CC=2 SCAR=17.9
Pod undocumented
130 0 my $self = shift;
131 0 my ($sub_ref) = @_;
132 0 ▶ $self->{_on_expression_match} = $sub_ref if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
133 }
134  
135 0 ▶sub get_expressions{
Subroutine get_expressions: not called CC=1 SCAR=6.9
Pod undocumented
136 0 my $self = shift;
137 0 my @expressions = $self->{_search}->expression_keys;
138 0 return \@expressions;
139 }
140  
141 8 ▶sub start{
Subroutine start: called CC=1 SCAR=0.0
Pod undocumented
142 8 my $self = shift;
143 8 ▶ &find(sub {$self->_find_file(@_)}, $self->start_directory);
Subroutine __ANON__: called CC=1 SCAR=0.0
144 }
145  
146 314 ▶sub _find_file{
Subroutine _find_file: called CC=22 SCAR=35.9
147 314 my $self = shift;
148  
149 314 my $fullFileDir = $File::Find::dir;
150 314 my $fullFilePath = $File::Find::name;
151 314 ▶ return if $fullFileDir ne $self->start_directory && $self->recurse_subs == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $fullFileDir ne $self->start_directory and $self->recurse_subs == 0 26 288 314
Condition100%3/3
$fullFileDir ne $self->start_directory and $self->recurse_subs == 0
!ll&&!rl&&r
10418426
MC/DC100%2/2
$fullFileDir ne $self->start_directory and $self->recurse_subs == 0
$fullFileDir ne $self->start_directory $self->recurse_subs == 0
Truth table100%3/3
A and B
A= $fullFileDir ne $self->start_directoryB= $self->recurse_subs == 0
ABresult
0X0
100
111
152 288 my $extension = $self->backup_extension;
153 288 ▶ return if $fullFilePath =~ /$extension$/;
Branch: 1 branch
BranchTrueFalseTotal
if $fullFilePath =~ /$extension$/ 0 288 288
154 288 ▶ my $file_expression = $self->file_expression || '';
Condition100%2/2
$self->file_expression || ''
l!l
132156
MC/DC100%1/1
$self->file_expression || ''
$self->file_expression
Truth table100%2/2
A
A= $self->file_expression
Aresult
11
00
155 288 my @files = $self->files;
156 288 my $file_pass = 0;
157 288 ▶ return if $file_expression ne '' && $fullFilePath !~ /$file_expression/;
Branch: 1 branch
BranchTrueFalseTotal
if $file_expression ne "" and not $fullFilePath =~ /$file_expression/ 125 163 288
Condition100%3/3
$file_expression ne "" and not $fullFilePath =~ /$file_expression/
!ll&&!rl&&r
1567125
MC/DC100%2/2
$file_expression ne "" and not $fullFilePath =~ /$file_expression/
$file_expression ne "" not $fullFilePath =~ /$file_expression/
Truth table100%3/3
A and not(B)
A= $file_expression ne ""B= not $fullFilePath =~ /$file_expression/
ABresult
0X0
100
111
158 163 foreach my $file (@files)
159 278 ▶ {$file_pass = 1 if $fullFilePath =~ /\b$file\b/;}
Branch: 1 branch
BranchTrueFalseTotal
if $fullFilePath =~ /\b$file\b/ 7 271 278
160 163 ▶ return if $file_pass != 1 && @files > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $file_pass != 1 and @files > 0 149 14 163
Condition100%3/3
$file_pass != 1 and @files > 0
!ll&&!rl&&r
77149
MC/DC100%2/2
$file_pass != 1 and @files > 0
$file_pass != 1 @files > 0
Truth table100%3/3
A and B
A= $file_pass != 1B= @files > 0
ABresult
0X0
100
111
161  
162  
163 14 $self->_add_file($fullFilePath);
164 14 $self->_get_properties($fullFilePath);
165 14 ▶ $self->_get_stats($fullFilePath) if $self->{_files}->{$fullFilePath}->file;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_files"}{$fullFilePath}->file 14 0 14
166 14 ▶ return unless $self->{_on_file_match}->($self->{_files}->{$fullFilePath});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_on_file_match"}->($self->{"_files"}{$fullFilePath}) 0 14 14
167  
168 14 ▶ if($self->{_files}->{$fullFilePath}->file)
Branch: 5 branches
BranchTrueFalseTotal
if ($self->{'_files'}{$fullFilePath}->file) { } 14 0 14
elsif ($self->{'_files'}{$fullFilePath}->directory) { } 0 0 0
elsif ($self->{'_files'}{$fullFilePath}->socket_) { } 0 0 0
elsif ($self->{'_files'}{$fullFilePath}->pipe_) { } 0 0 0
elsif ($self->{'_files'}{$fullFilePath}->link_) { } 0 0 0
169 {
170 14 my $fileName = $fullFilePath;
171 14 $fileName =~ s/$fullFileDir//;
172 14 $fileName =~ s/^\///;
173 14 $self->{_files}->{$fullFilePath}->dir($fullFileDir);
174 14 $self->{_files}->{$fullFilePath}->name($fileName);
175 14 ▶ if($self->{_files}->{$fullFilePath}->text)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_files'}{$fullFilePath}->text) { } 13 1 14
elsif ($self->{'_files'}{$fullFilePath}->binary) { } 1 0 1
176 {
177 13 $self->{_search}->file_text_cnt($self->{_search}->file_text_cnt+1);
178 13 $self->_process_file($fullFilePath);
179 }
180 elsif($self->{_files}->{$fullFilePath}->binary)
181 {
182 1 $self->{_search}->file_binary_cnt($self->{_search}->file_binary_cnt+1);
183 }
184 else
185 {
186 0 $self->{_search}->file_unknown_cnt($self->{_search}->file_unknown_cnt+1);
187 }
188 14 $self->{_search}->file_cnt($self->{_search}->file_cnt+1);
189 14 ▶ print "$fullFileDir/$fileName\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Searcher::DEBUG 0 14 14
190  
191 }
192 elsif($self->{_files}->{$fullFilePath}->directory)
193 {
194 0 $self->{_files}->{$fullFilePath}->dir($fullFilePath);
195 0 $self->{_files}->{$fullFilePath}->name('');
196 0 $self->{_search}->dir_cnt($self->{_search}->dir_cnt+1);
197 0 ▶ print "$fullFilePath\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Searcher::DEBUG 0 0 0
198 }
199 elsif($self->{_files}->{$fullFilePath}->socket_)
200 0 {$self->{_search}->socket_cnt($self->{_search}->socket_cnt+1);}
201 elsif($self->{_files}->{$fullFilePath}->pipe_)
202 0 {$self->{_search}->pipe_cnt($self->{_search}->pipe_cnt+1);}
203 elsif($self->{_files}->{$fullFilePath}->link_)
204 0 {$self->{_search}->link_cnt($self->{_search}->link_cnt+1);}
205 else
206 0 {$self->{_search}->unknown_cnt($self->{_search}->unknown_cnt+1);}
207  
208 }
209 13 ▶sub _process_file{
Subroutine _process_file: called CC=26 SCAR=35.3
210 13 my $self = shift;
211 13 my ($file) = @_;
212 13 my @expressions = @{$self->{_expressions}};
213 13 my $contents='';
214 13 ▶ $self->_backup($file) if $self->do_backup;
Branch: 1 branch
BranchTrueFalseTotal
if $self->do_backup 3 10 13
215 13 ▶ $self->_archive($file) if $self->do_archive;
Branch: 1 branch
BranchTrueFalseTotal
if $self->do_archive 3 10 13
216 13 $self->{_search}->add_files_matched($file);
217  
218  
219 13 my $lock = new File::Flock $file;
220 13 ▶ open(FILE, $file) || die "Cannot read file $file\n";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $file or die "Cannot read file $file\n" 13 0 13
221 13 my @contents = <FILE>;
222 13 $contents = join("", @contents);
223 13 foreach my $expression (@expressions)
224 {
225 5 ▶ next if $self->{_search}->expression($expression)->skip_expression;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_search"}->expression($expression)->skip_expression 0 5 5
226 5 my ($match_cnt,$replace_cnt,$skip_next,$do_file,$do_all,$new_match_cnt) = (0)x6;
227 5 $self->{_search}->expression($expression)->add_files_matched($file);
228 5 $do_all = $self->expression($expression)->do_all;
229 5 my ($search, $replace, $options_search, $options_replace) = $self->_get_search($expression);
230 5 $search = "(?" . $options_search . ")" . $search;
231 5 ▶ while($contents =~ m/$search/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($contents =~ /$search/g) 56 5 61
232 {
233 56 my $match = Match->new(match=>$&,pre=>$`,post=>$',last=>$+,start_offset=>@-,end_offset=>@+,contents=>$contents);
234 # to support old perl
235 56 $match->match("$&"); $match->pre("$`"); $match->post("$'"); $match->last("$+"); $match->start_offset("@-"); $match->end_offset("@+"); $match->contents("$contents");
236 56 my $return_status = 0;
237 56 ▶ $return_status = $self->{_on_expression_match}->($match, $self->{_search}->expression($expression)) if $do_file != 1 && $do_all != 1 && $new_match_cnt < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $do_file != 1 and $do_all != 1 and $new_match_cnt < 1 11 45 56
Condition50%3/6
$do_file != 1 and $do_all != 1 and $new_match_cnt < 1
!ll&&!rl&&r
04511
$do_file != 1 and $do_all != 1
!ll&&!rl&&r
0056
MC/DC33%1/3
$do_file != 1 and $do_all != 1 and $new_match_cnt < 1
$do_file != 1 $do_all != 1 $new_match_cnt < 1
Truth table50%2/4
A and B and C
A= $do_file != 1B= $do_all != 1C= $new_match_cnt < 1
ABCresult
0XX0
10X0
1100
1111
238 56 ▶ $contents = $return_status and next if $return_status !~ /\d+/ && $return_status ne '';
Branch: 1 branch
BranchTrueFalseTotal
if not $return_status =~ /\d+/ and $return_status ne "" 0 56 56
Condition25%2/8
!($return_status =~ /\d+/) && $return_status ne '' && (($contents = $return_status) && (next))
!ll&&!rl&&r
5600
not $return_status =~ /\d+/ and $return_status ne ""
!ll&&!rl&&r
5600
$contents = $return_status and next
!ll
00
MC/DC0%0/3
!($return_status =~ /\d+/) && $return_status ne '' && (($contents = $return_status) && (next))
not $return_status =~ /\d+/ $return_status ne "" $contents = $return_status
Truth table25%1/4
not(A) and B && C
A= not $return_status =~ /\d+/B= $return_status ne ""C= $contents = $return_status
ABCresult
0XX0
10X0
1100
1111
239 56 ▶ $self->expression($expression)->do_all(1) and $do_all = 1 if $return_status == 100;
Branch: 1 branch
BranchTrueFalseTotal
if $return_status == 100 0 56 56
Condition20%1/5
$return_status == 100 && ($self->expression($expression)->do_all(1) && ($do_all = 1))
!ll
560
$self->expression($expression)->do_all(1) and $do_all = 1
!ll&&!rl&&r
000
MC/DC0%0/3
$return_status == 100 && ($self->expression($expression)->do_all(1) && ($do_all = 1))
$return_status == 100 $self->expression($expression)->do_all(1) $do_all = 1
Truth table0%0/4
A && B and C
A= $return_status == 100B= $self->expression($expression)->do_all(1)C= $do_all = 1
ABCresult
0XX0
10X0
1100
1111
240 56 ▶ $do_file = 1 if $return_status == 10;
Branch: 1 branch
BranchTrueFalseTotal
if $return_status == 10 0 56 56
241 56 ▶ $self->expression($expression)->skip_expression(1) and last if $return_status == -100;
Branch: 1 branch
BranchTrueFalseTotal
if $return_status == -100 0 56 56
Condition25%1/4
$return_status == -100 && ($self->expression($expression)->skip_expression(1) && (last))
!ll
560
$self->expression($expression)->skip_expression(1) and last
!ll
00
MC/DC0%0/2
$return_status == -100 && ($self->expression($expression)->skip_expression(1) && (last))
$return_status == -100 $self->expression($expression)->skip_expression(1)
Truth table33%1/3
A && B
A= $return_status == -100B= $self->expression($expression)->skip_expression(1)
ABresult
0X0
100
111
242 56 ▶ last if $return_status == -10;
Branch: 1 branch
BranchTrueFalseTotal
if $return_status == -10 0 56 56
243 56 ▶ $skip_next = 1 if $return_status == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $return_status == -1 0 56 56
244  
245 56 ▶ $skip_next = 1 if $match->match eq $replace;
Branch: 1 branch
BranchTrueFalseTotal
if $match->match eq $replace 0 56 56
246 56 ▶ $skip_next = 1 if $new_match_cnt > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $new_match_cnt > 0 45 11 56
247 56 ▶ unless($skip_next)
Branch: 1 branch
BranchTrueFalseTotal
unless ($skip_next) 11 45 56
248 {
249 11 my $body = $match->match;
250 11 eval ("\$body =~ s/$search/$replace/$options_replace");
251 11 $replace_cnt++;
252 11 $match_cnt++;
253 11 $contents = $match->pre . $body . $match->post;
254 11 $new_match_cnt = $match_cnt+1;
255 }
256 56 $new_match_cnt--;
257 56 $skip_next = 0;
258 }
259 5 ▶ $self->{_search}->expression($expression)->add_files_replaced($file) if $replace_cnt > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $replace_cnt > 0 3 2 5
260 5 $self->{_search}->expression($expression)->replacements($file, $replace_cnt);
261 5 $self->{_search}->expression($expression)->matches($file, $match_cnt);
262 }
263 13 close(FILE);
264 13 ▶ if($self->{_search}->do_replace)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_search"}->do_replace) 2 11 13
265 {
266 2 ▶ open(FILE, ">$file") || die "Cannot read file $file\n";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or die "Cannot read file $file\n" 2 0 2
267 2 print FILE $contents;
268 2 close(FILE);
269 }
270 }
271  
272 5 ▶sub _get_search{
Subroutine _get_search: called CC=19 SCAR=30.6
273 5 my $self = shift;
274 5 my ($expression) = @_;
275 5 ▶ my $options = $self->{_search}->expression($expression)->options || '';
Condition50%1/2
$self->{'_search'}->expression($expression)->options || ''
l!l
50
MC/DC0%0/1
$self->{'_search'}->expression($expression)->options || ''
$self->{'_search'}->expression($expression)->options
Truth table50%1/2
A
A= $self->{'_search'}->expression($expression)->options
Aresult
11
00
276 5 ▶ my $search = $self->{_search}->expression($expression)->search || '';
Condition50%1/2
$self->{'_search'}->expression($expression)->search || ''
l!l
50
MC/DC0%0/1
$self->{'_search'}->expression($expression)->search || ''
$self->{'_search'}->expression($expression)->search
Truth table50%1/2
A
A= $self->{'_search'}->expression($expression)->search
Aresult
11
00
277 5 ▶ my $replace = $self->{_search}->expression($expression)->replace || '';
Condition50%1/2
$self->{'_search'}->expression($expression)->replace || ''
l!l
50
MC/DC0%0/1
$self->{'_search'}->expression($expression)->replace || ''
$self->{'_search'}->expression($expression)->replace
Truth table50%1/2
A
A= $self->{'_search'}->expression($expression)->replace
Aresult
11
00
278 5 ▶ my $multiline = 1 if $self->{_search}->expression($expression)->multiline || $options =~ /m/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_search"}->expression($expression)->multiline or $options =~ /m/ 2 3 5
Condition66%2/3
$self->{"_search"}->expression($expression)->multiline or $options =~ /m/
l!l&&r!l&&!r
023
MC/DC50%1/2
$self->{"_search"}->expression($expression)->multiline or $options =~ /m/
$self->{"_search"}->expression($expression)->multiline $options =~ /m/
Truth table66%2/3
A or B
A= $self->{"_search"}->expression($expression)->multilineB= $options =~ /m/
ABresult
1X1
011
000
279 5 ▶ my $singleline = 1 if $self->{_search}->expression($expression)->singleline || $options =~ /s/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_search"}->expression($expression)->singleline or $options =~ /s/ 2 3 5
Condition66%2/3
$self->{"_search"}->expression($expression)->singleline or $options =~ /s/
l!l&&r!l&&!r
023
MC/DC50%1/2
$self->{"_search"}->expression($expression)->singleline or $options =~ /s/
$self->{"_search"}->expression($expression)->singleline $options =~ /s/
Truth table66%2/3
A or B
A= $self->{"_search"}->expression($expression)->singlelineB= $options =~ /s/
ABresult
1X1
011
000
280 5 ▶ my $case_insensitive = 1 if $self->{_search}->expression($expression)->case_insensitive || $options =~ /i/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_search"}->expression($expression)->case_insensitive or $options =~ /i/ 4 1 5
Condition66%2/3
$self->{"_search"}->expression($expression)->case_insensitive or $options =~ /i/
l!l&&r!l&&!r
041
MC/DC50%1/2
$self->{"_search"}->expression($expression)->case_insensitive or $options =~ /i/
$self->{"_search"}->expression($expression)->case_insensitive $options =~ /i/
Truth table66%2/3
A or B
A= $self->{"_search"}->expression($expression)->case_insensitiveB= $options =~ /i/
ABresult
1X1
011
000
281 5 ▶ my $eval_replacement = 1 if $self->{_search}->expression($expression)->eval_replacement || $options =~ /e/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_search"}->expression($expression)->eval_replacement or $options =~ /e/ 1 4 5
Condition66%2/3
$self->{"_search"}->expression($expression)->eval_replacement or $options =~ /e/
l!l&&r!l&&!r
014
MC/DC50%1/2
$self->{"_search"}->expression($expression)->eval_replacement or $options =~ /e/
$self->{"_search"}->expression($expression)->eval_replacement $options =~ /e/
Truth table66%2/3
A or B
A= $self->{"_search"}->expression($expression)->eval_replacementB= $options =~ /e/
ABresult
1X1
011
000
282 5 ▶ my $extend = 1 if $self->{_search}->expression($expression)->extend || $options =~ /x/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_search"}->expression($expression)->extend or $options =~ /x/ 0 5 5
Condition33%1/3
$self->{"_search"}->expression($expression)->extend or $options =~ /x/
l!l&&r!l&&!r
005
MC/DC0%0/2
$self->{"_search"}->expression($expression)->extend or $options =~ /x/
$self->{"_search"}->expression($expression)->extend $options =~ /x/
Truth table33%1/3
A or B
A= $self->{"_search"}->expression($expression)->extendB= $options =~ /x/
ABresult
1X1
011
000
283  
284 5 my $options_search = '';
285 5 ▶ $options_search .= "m" if $multiline;
Branch: 1 branch
BranchTrueFalseTotal
if $multiline 2 3 5
286 5 ▶ $options_search .= "i" if $case_insensitive;
Branch: 1 branch
BranchTrueFalseTotal
if $case_insensitive 4 1 5
287 5 ▶ $options_search .= "s" if $singleline;
Branch: 1 branch
BranchTrueFalseTotal
if $singleline 2 3 5
288 5 ▶ $options_search .= "x" if $extend;
Branch: 1 branch
BranchTrueFalseTotal
if $extend 0 5 5
289 5 my $options_replace = $options_search;
290 5 ▶ $options_replace .= "e" if $eval_replacement;
Branch: 1 branch
BranchTrueFalseTotal
if $eval_replacement 1 4 5
291  
292 5 return($search, $replace, $options_search, $options_replace);
293  
294 }
295  
296 3 ▶sub _archive{
Subroutine _archive: called CC=2 SCAR=7.3
297 3 my $self = shift;
298 1 ▶ use Archive::Tar;
Subroutine BEGIN: called CC=1 SCAR=0.0
299 3 my ($file) = @_;
300  
301 3 ▶ unless($self->{_search}->archive)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_search"}->archive) 0 3 3
302 {
303 0 my $archive = $self->{_search}->archive(time . ".tgz");
304 0 my $dir = $self->{_search}->start_directory;
305 0 Archive::Tar->create_archive("$dir/$archive", 9, "$file");
306 0 return;
307 }
308 3 my $tar = Archive::Tar->new();
309 3 my $archive = $self->{_search}->archive;
310 3 my $dir = $self->{_search}->start_directory;
311 3 $archive = "$dir/$archive";
312 3 $tar->read($archive,1);
313 3 $tar->add_files($file);
314 3 $tar->write($archive,9);
315 }
316  
317 3 ▶sub _backup{
Subroutine _backup: called CC=2 SCAR=7.0
318 3 my $self = shift;
319 3 my ($file) = @_;
320 3 my $extension = $self->backup_extension;
321 3 ▶ return if $file =~ /$extension$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /$extension$/ 0 3 3
322 3 copy($file, $file . $extension);
323 }
324  
325  
326 14 ▶sub _add_file{
Subroutine _add_file: called CC=2 SCAR=7.0
327 14 my $self = shift;
328 14 my ($file) = @_;
329 14 ▶ return if exists $self->{_files}->{$file};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_files"}{$file} 0 14 14
330 14 $self->{_files}->{$file} = Properties->new(readable_e=>'0',writable_e=>'0',executable_e=>'0',readable_r=>'0',writable_r=>'0',executable_r=>'0',owned_e=>'0',owned_r=>'0',exist=>'0',exist_non_zero=>'0',zero_size=>'0',file=>'0',directory=>'0',link_=>'0',pipe_=>'0',socket_=>'0',block=>'0',character=>'0',setuid_bit=>'0',setgid_bit=>'0',sticky_bit=>'0',opened_tty=>'0',text=>'0',binary=>'0',path=> $file,);
331 }
332  
333  
334 14 ▶sub _get_properties{
Subroutine _get_properties: called CC=2 SCAR=6.9
335 14 my $self = shift;
336 14 my ($file) = @_;
337 14 my %p = (readable_e=>'-r',writable_e=>'-w',executable_e=>'-x',readable_r=>'-R',writable_r=>'-W',executable_r=>'-x',owned_e=>'-o',owned_r=>'-O',exist=>'-e',exist_non_zero=>'-s',zero_size=>'-z',file=>'-f',directory=>'-d',link_=>'-l',pipe_=>'-p',socket_=>'-S',block=>'-b',character=>'-c',setuid_bit=>'-u',setgid_bit=>'-g',sticky_bit=>'-k',opened_tty=>'-t',text=>'-T',binary=>'-B',);
338 14 foreach (keys %p){eval "\$self->{_files}->{\$file}->$_\(1) if $p{$_} \$file;";}
339 }
340  
341 14 ▶sub _get_stats{
Subroutine _get_stats: called CC=3 SCAR=11.0
342 14 my $self = shift;
343 14 my ($file) = @_;
344 14 my @p = qw/device_code inode_number mode_flags link_cnt user_id group_id device_type size_bytes time_access_seconds time_modified_seconds time_status_seconds block_system block_file/;
345 14 my($device_code, $inode_number, $mode_flags, $link_cnt, $user_id, $group_id, $device_type, $size_bytes, $time_access_seconds, $time_modified_seconds, $time_status_seconds, $block_system, $block_file)
346 = stat($file);
347
348 14 foreach (@p){eval("\$self->{_files}->{\$file}->stats(new Stats);"); }
349 14 foreach (@p){eval("\$self->{_files}->{\$file}->stats->$_\(\$$_);"); }
350  
351 # extra stats
352 14 $self->{_files}->{$file}->stats->time_access_string($self->_seconds_2_string_date($time_access_seconds));
353 14 $self->{_files}->{$file}->stats->time_modified_string($self->_seconds_2_string_date($time_modified_seconds));
354 14 $self->{_files}->{$file}->stats->time_status_string($self->_seconds_2_string_date($time_status_seconds));
355 14 $self->{_files}->{$file}->stats->mode_string($self->_file_mode_string($mode_flags, $file));
356 }
357  
358 7 ▶sub _get_cwd{
Subroutine _get_cwd: called CC=1 SCAR=0.0
359 7 my $self = shift;
360 7 require Cwd;
361 7 return Cwd::getcwd;
362 }
363  
364 42 ▶sub _seconds_2_string_date{
Subroutine _seconds_2_string_date: called CC=1 SCAR=0.0
365 42 my $self = shift;
366 42 my($time)=@_;
367 42 require Time::localtime;
368 42 $time=Time::localtime::ctime($time);
369 42 return $time;
370 }
371  
372  
373 14 ▶sub _file_mode_string{
Subroutine _file_mode_string: called CC=5 SCAR=18.1
374 14 my $self = shift;
375 14 my($mode, $filename) =@_;
376 14 my($modestring);
377  
378 0 ▶ if (-l $filename){$modestring = "1";}
Branch: 2 branches
BranchTrueFalseTotal
if (-l $filename) { } 0 14 14
elsif (-d $filename) { } 0 14 14
379 0 elsif (-d $filename){$modestring = "d";}
380 14 else{$modestring = "-";}
381 14 my $oo = $mode & 07;
382 14 my $go = ($mode >> 3) & 07;
383 14 my $uo = ($mode >> 6) & 07;
384  
385 14 $modestring .= ("---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx")[$uo];
386 0 ▶ if (-u $filename){chop($modestring);$modestring .= "s"}
Branch: 1 branch
BranchTrueFalseTotal
if (-u $filename) 0 14 14
387 14 $modestring .= ("---", "--x", "-w-", "-wx", "r--", "r-x", "rw-","rwx")[$go];
388 0 ▶ if (-g $filename){chop($modestring);$modestring .= "s"}
Branch: 1 branch
BranchTrueFalseTotal
if (-g $filename) 0 14 14
389 14 $modestring .= ("---", "--x", "-w-", "-wx", "r--", "r-x", "rw-","rwx")[$oo];
390  
391 14 return $modestring;
392 }
393  
394 1489 ▶sub AUTOLOAD{
Subroutine AUTOLOAD: called CC=1 SCAR=0.2
395 1489 my($package, $function) = ($AUTOLOAD =~ /(.*)::(.*)/);
396 1489 my($self, @args)= @_;
397 # print "$AUTOLOAD, $self," . join(', ', @args) ."\n" if $DEBUG;
398 1489 return $self->{_search}->$function(@args);
399 0 croak "An Undefined subroutine &$AUTOLOAD";
400 }
401  
402 0 ▶sub DESTROY{}
Subroutine DESTROY: not called CC=1 SCAR=0.0
403  
404 1 1;
405 __END__
↑ Summary