| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::CmdDirs::Traverser::Base; | 
| 2 | 2 |  |  | 2 |  | 10 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 53 |  | 
| 3 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 42 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 2 |  |  | 2 |  | 207917 | use Term::ANSIColor; | 
|  | 2 |  |  |  |  | 22557 |  | 
|  | 2 |  |  |  |  | 811 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | sub new { | 
| 8 | 2 |  |  | 2 | 0 | 7 | my ($class, $command, $topDir, $dirs) = @_; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 2 |  |  |  |  | 5 | my $self = {}; | 
| 11 | 2 |  |  |  |  | 41 | bless $self, $class; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 2 |  |  |  |  | 23 | $self->{'command'} = $command; | 
| 14 | 2 |  |  |  |  | 7 | $self->{'topDir'} = $topDir; | 
| 15 | 2 |  |  |  |  | 10 | $self->{'dirs'} = $dirs; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 2 |  |  |  |  | 6 | return $self; | 
| 18 |  |  |  |  |  |  | } | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # Return false to skip this directory | 
| 21 |  |  |  |  |  |  | sub test { | 
| 22 |  |  |  |  |  |  | # Override this | 
| 23 | 0 |  |  | 0 | 0 | 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 |  |  |  |  |  |  | sub traverse { | 
| 29 | 2 |  |  | 2 | 0 | 6 | my ($self, $quiet) = @_; | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 2 |  |  |  |  | 5 | my $command = $self->{'command'}; | 
| 32 | 2 |  |  |  |  | 7 | my $topDir = $self->{'topDir'}; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 2 |  |  |  |  | 2 | my @dirs = @{$self->{'dirs'}}; | 
|  | 2 |  |  |  |  | 7 |  | 
| 35 | 2 |  |  |  |  | 5 | foreach my $dir (@dirs) { | 
| 36 | 4 | 50 |  |  |  | 75 | next if ! -d $dir; | 
| 37 | 4 | 100 |  |  |  | 62 | next if ! $self->test($dir); | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | # Tell the user what command is going to be run | 
| 40 | 2 | 50 |  |  |  | 7 | unless ($quiet) { | 
| 41 | 0 |  |  |  |  | 0 | print color 'bold green'; | 
| 42 | 0 |  |  |  |  | 0 | print "Performing `$command` in <$dir>\n"; | 
| 43 | 0 |  |  |  |  | 0 | print color 'reset'; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | # Descend into the directory & run the command | 
| 47 | 2 |  |  |  |  | 12 | chdir $dir; | 
| 48 | 2 |  |  |  |  | 13503 | system("$command"); | 
| 49 | 2 |  |  |  |  | 104 | chdir $topDir; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 2 |  |  |  |  | 158 | print "\n"; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 2 |  |  |  |  | 89 | return 1 | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | 1; |