Permalink
Browse files

minor refactoring

  • Loading branch information...
1 parent 5cd41ec commit b03eb34c5ca9c63b66dc7ef044e6fb6d14af5078 @agentzh committed Apr 20, 2009
Showing with 43 additions and 15 deletions.
  1. +3 −0 Makefile.PL
  2. +12 −1 bin/fornodes
  3. +10 −14 lib/SSH/Batch/ForNodes.pm
  4. +18 −0 t/ForNodes.pm
View
@@ -10,6 +10,9 @@ all_from ('lib/SSH/Batch.pm');
requires ('Set::Scalar' => '1.23');
requires ('File::HomeDir' => '0.86');
+requires ('Net::OpenSSH' => '0.34');
+
+build_requires ('IPC::Run3');
no_index( directory => qw< t inc doc share demo > );
View
@@ -2,9 +2,20 @@
use strict;
use warnings;
+
+use lib 'lib';
+use File::HomeDir;
use SSH::Batch::ForNodes;
-SSH::Batch::ForNodes::load_rc($RcFile);
+my $home = File::HomeDir->my_home;
+if (!defined $home) {
+ die "Can't find the home for the current user.\n";
+}
+my $rcfile = "$home/.fornodesrc";
+open my $rc, $rcfile or
+ die "Can't open $rcfile for reading: $!\n";
+SSH::Batch::ForNodes::load_rc($rc, $rcfile);
+
my $expr = join ' ', @ARGV or
die "No argument specified.\n";
my $set = parse_expr($expr);
View
@@ -6,9 +6,9 @@ use warnings;
our $VERSION = '0.001';
use Set::Scalar;
-use File::HomeDir;
-sub load_rc ($);
+sub clear_universe ();
+sub load_rc ($$);
sub parse_line ($$);
sub parse_expr ($);
sub parse_term ($);
@@ -17,18 +17,15 @@ sub expand_seg ($@);
sub expand_wildcards ($);
my $RangePat = qr/\w+(?:-\w+)?/;
-my $home = File::HomeDir->my_home;
-if (!defined $home) {
- die "Can't find the home for the current user.\n";
-}
-my $RcFile = "$home/.fornodesrc";
my %Vars;
-my $HostUniverse = Set::Scalar->new;
+our $HostUniverse = Set::Scalar->new;
+
+sub clear_universe () {
+ $HostUniverse->empty;
+}
-sub load_rc ($) {
- my $rcfile = shift;
- open my $rc, $rcfile or
- die "Can't open $rcfile for reading: $!\n";
+sub load_rc ($$) {
+ my ($rc, $rcfile) = @_;
my $accum_ln;
while (<$rc>) {
s/\#.*//;
@@ -128,8 +125,7 @@ sub parse_term ($) {
}
my $set = $Vars{$var};
if (!defined $set) {
- die "Variable $var not defined.\n",
- "\t(Maybe you forgot to define it in $RcFile?)\n";
+ die "Variable $var not defined.\n";
}
return $set;
}
View
@@ -0,0 +1,18 @@
+package t::ForNodes;
+
+use Test::Base -Base;
+
+our @#XPORT = qw( run_tests );
+
+sub run_tests () {
+ for my $block (blocks()) {
+ run_test($block);
+ }
+}
+
+sub run_test ($) {
+ my $block = shift;
+ my $name = $block->name;
+}
+
+1;

0 comments on commit b03eb34

Please sign in to comment.