App-CmdDirs

 view release on metacpan or  search on metacpan

bin/cmddirs  view on Meta::CPAN

  
      if ($self->{'options'}{'all'}) {
          $traverser = App::CmdDirs::Traverser::Base->new($command, $topDir, $dirs);
      } elsif ($self->{'options'}->{'git'} || $command =~ /git/) {
          require App::CmdDirs::Traverser::Git;
          $traverser = App::CmdDirs::Traverser::Git->new($command, $topDir, $dirs);
      } elsif ($self->{'options'}->{'svn'} || $command =~ /svn/) {
          require App::CmdDirs::Traverser::Subversion;
          $traverser = App::CmdDirs::Traverser::Subversion->new($command, $topDir, $dirs);
      } else {
          $traverser = App::CmdDirs::Traverser::Base->new($command, $topDir, $dirs);
      }
  
      return $traverser;
  }
  
  1;
APP_CMDDIRS

$fatpacked{"App/CmdDirs/Traverser/Base.pm"} = <<'APP_CMDDIRS_TRAVERSER_BASE';
  package App::CmdDirs::Traverser::Base;
  use strict;
  use warnings;
  
  use Term::ANSIColor;
  
  sub new {
      my ($class, $command, $topDir, $dirs) = @_;
  
      my $self = {};
      bless $self, $class;
  
      $self->{'command'} = $command;
      $self->{'topDir'} = $topDir;
      $self->{'dirs'} = $dirs;
  
      return $self;
  }
  
  # Return false to skip this directory
  sub test {
      # Override this
      return 1;
  }
  
  # Run this class' test() on each directory.  If the test passes, descend
  # into that directory, run $command, and return to the top directory.
  sub traverse {
      my ($self, $quiet) = @_;
  
      my $command = $self->{'command'};
      my $topDir = $self->{'topDir'};
  
      my @dirs = @{$self->{'dirs'}};
      foreach my $dir (@dirs) {
          next if ! -d $dir;
          next if ! $self->test($dir);
  
          # Tell the user what command is going to be run
          unless ($quiet) {
              print color 'bold green';
              print "Performing `$command` in <$dir>\n";
              print color 'reset';
          }
  
          # Descend into the directory & run the command
          chdir $dir;
          system("$command");
          chdir $topDir;
  
          print "\n";
      }
  
      return 1
  }
  
  1;
APP_CMDDIRS_TRAVERSER_BASE

$fatpacked{"App/CmdDirs/Traverser/Git.pm"} = <<'APP_CMDDIRS_TRAVERSER_GIT';
  package App::CmdDirs::Traverser::Git;
  use base 'App::CmdDirs::Traverser::Base';
  use strict;
  use warnings;
  
  # Return false if the passed directory does not have a .git subdirectory
  sub test {
      my ($self, $dir) = @_;
  
      return (-d "$dir/.git");
  }
  
  1;
APP_CMDDIRS_TRAVERSER_GIT

$fatpacked{"App/CmdDirs/Traverser/Subversion.pm"} = <<'APP_CMDDIRS_TRAVERSER_SUBVERSION';
  package App::CmdDirs::Traverser::Subversion;
  use base 'App::CmdDirs::Traverser::Base';
  use strict;
  use warnings;
  
  # Return false if the passed directory does not have a .svn subdirectory
  sub test {
      my ($self, $dir) = @_;
  
      return (-d "$dir/.svn");
  }
  
  1;
APP_CMDDIRS_TRAVERSER_SUBVERSION

s/^  //mg for values %fatpacked;

unshift @INC, sub {
  if (my $fat = $fatpacked{$_[1]}) {
    open my $fh, '<', \$fat
      or die "FatPacker error loading $_[1] (could be a perl installation issue?)";
    return $fh;
  }
  return
};



( run in 0.647 second using v1.01-cache-2.11-cpan-f56aa216473 )