| 1 | package App::CmdDirs::Traverser::Base; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use Term::ANSIColor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 8 | 2 | my ($class, $command, $topDir, $dirs) = @_; | |||||||||
| 9 | |||||||||||
| 10 | 2 | my $self = {}; | |||||||||
| 11 | 2 | bless $self, $class; | |||||||||
| 12 | |||||||||||
| 13 | 2 | $self->{'command'} = $command; | |||||||||
| 14 | 2 | $self->{'topDir'} = $topDir; | |||||||||
| 15 | 2 | $self->{'dirs'} = $dirs; | |||||||||
| 16 | |||||||||||
| 17 | 2 | return $self; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | # Return false to skip this directory | ||||||||||
| 21 | 0 | ▶ | sub test { | ||||||||
|
Subroutine
test: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 22 | # Override this | ||||||||||
| 23 | 0 | return 1; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | # Run this class' test() on each directory. If the test passes, descend | ||||||||||
| 27 | # into that directory, run $command, and return to the top directory. | ||||||||||
| 28 | 2 | ▶ | sub traverse { | ||||||||
|
Subroutine
traverse: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||
| 29 | 2 | my ($self, $quiet) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 2 | my $command = $self->{'command'}; | |||||||||
| 32 | 2 | my $topDir = $self->{'topDir'}; | |||||||||
| 33 | |||||||||||
| 34 | 2 | my @dirs = @{$self->{'dirs'}}; | |||||||||
| 35 | 2 | foreach my $dir (@dirs) { | |||||||||
| 36 | 4 | ▶ | next if ! -d $dir; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 4 | ▶ | next if ! $self->test($dir); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | |||||||||||
| 39 | # Tell the user what command is going to be run | ||||||||||
| 40 | 2 | ▶ | unless ($quiet) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | print color 'bold green'; | |||||||||
| 42 | 0 | print "Performing `$command` in <$dir>\n"; | |||||||||
| 43 | 0 | print color 'reset'; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | # Descend into the directory & run the command | ||||||||||
| 47 | 2 | chdir $dir; | |||||||||
| 48 | 2 | system("$command"); | |||||||||
| 49 | 2 | chdir $topDir; | |||||||||
| 50 | |||||||||||
| 51 | 2 | print "\n"; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 2 | return 1 | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 2 | 1; | |||||||||