diff options
| author | Paul Buetow <paul@buetow.org> | 2012-04-19 23:26:40 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2012-04-19 23:26:40 +0200 |
| commit | 86c242f505280ee56f8c995bd8099bd4f026b6d3 (patch) | |
| tree | bdb612e89264a6b8a44cd824d2da7a7b9f5ec2ef | |
| parent | a152c0d0520dd00c863734a1720a528099779341 (diff) | |
refactoring
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | lib/Loadbars/Main.pm | 67 | ||||
| -rwxr-xr-x | loadbars | 57 |
3 files changed, 38 insertions, 88 deletions
@@ -1,4 +1,4 @@ perltidy: find . -name \*.pm | xargs perltidy -b - find . -name \*.pl | xargs perltidy -b + perltidy -b loadbars find . -name \*.bak -delete diff --git a/lib/Loadbars/Main.pm b/lib/Loadbars/Main.pm index 3a0239a..5b8f161 100644 --- a/lib/Loadbars/Main.pm +++ b/lib/Loadbars/Main.pm @@ -288,7 +288,7 @@ sub set_dimensions ($$) { } } -sub main_loop ($@) { +sub loop ($@) { my ( $dispatch, @threads ) = @_; my $num_stats = 1; @@ -304,18 +304,18 @@ sub main_loop ($@) { -resizeable => 1, ); - my $fontbase = 'fonts/font.png'; + my $font = do { + my $fontbase = 'fonts/font.png'; - if ( -f "./$fontbase" ) { - $C{font} = "./$fontbase"; - - } - elsif ( -f "/usr/share/loadbars/$fontbase" ) { - $C{font} = "/usr/share/loadbars/$fontbase"; - } + if ( -f "./$fontbase" ) { + "./$fontbase"; + } + elsif ( -f "/usr/share/loadbars/$fontbase" ) { + "/usr/share/loadbars/$fontbase"; + } + }; - say( "Foo:" . $C{font} ); - SDL::Font->new( $C{font} )->use(); + SDL::Font->new($font)->use(); my $rects = {}; my %prev_stats; @@ -884,49 +884,4 @@ sub main_loop ($@) { exit Loadbars::Constants->SUCCESS; } -# Recursuve function -sub get_cluster_hosts ($;$); - -sub get_cluster_hosts ($;$) { - my ( $cluster, $recursion ) = @_; - - unless ( defined $recursion ) { - $recursion = 1; - - } - elsif ( $recursion > Loadbars::Constants->CSSH_MAX_RECURSION ) { - error( "CSSH_MAX_RECURSION reached. Infinite circle loop in " - . Loadbars::Constants->CSSH_CONFFILE - . "?" ); - } - - open my $fh, Loadbars::Constants->CSSH_CONFFILE - or error( "$!: " . Loadbars::Constants->CSSH_CONFFILE ); - my $hosts; - - while (<$fh>) { - if (/^$cluster\s*(.*)/) { - $hosts = $1; - last; - } - } - - close $fh; - - unless ( defined $hosts ) { - error( "No such cluster in " - . Loadbars::Constants->CSSH_CONFFILE - . ": $cluster" ) - unless defined $recursion; - - return ($cluster); - } - - my @hosts; - push @hosts, get_cluster_hosts $_, ( $recursion + 1 ) - for ( split /\s+/, $hosts ); - - return @hosts; -} - 1; @@ -17,45 +17,40 @@ use Loadbars::HelpDispatch; use Loadbars::Shared; use Loadbars::Utils; -sub main () { - my ( $hosts, $dispatch ) = Loadbars::HelpDispatch::create; - my $usage; +my ( $hosts, $dispatch ) = Loadbars::HelpDispatch::create; +my $usage; - say(Loadbars::Constants->VERSION . ' ' . Loadbars::Constants->COPYRIGHT); +say( Loadbars::Constants->VERSION . ' ' . Loadbars::Constants->COPYRIGHT ); - Loadbars::Config::read; +Loadbars::Config::read; - GetOptions( 'help|?' => \$usage, $dispatch->('options') ); +GetOptions( 'help|?' => \$usage, $dispatch->('options') ); - if ( defined $usage ) { - say $dispatch->('usage'); - exit Loadbars::Constants->SUCCESS; - } - - Loadbars::Main::set_showcores_regexp; - - my @hosts = map { - my ( $a, $b ) = split /\@/, $_; - defined $b ? "$b:$a" : $a; - } split ',', $$hosts; +if ( defined $usage ) { + say $dispatch->('usage'); + exit Loadbars::Constants->SUCCESS; +} - if ( @hosts || defined $Loadbars::Main::C{cluster} ) { - push @hosts, Loadbars::Main::get_cluster_hosts $C{cluster} - if defined $Loadbars::Main::C{cluster}; - system 'ssh-add'; +Loadbars::Main::set_showcores_regexp; - } - else { - Loadbars::Main::say $dispatch->('usage'); - exit Loadbars::Constants->E_NOHOST; - } +my @hosts = map { + my ( $a, $b ) = split /\@/, $_; + defined $b ? "$b:$a" : $a; +} split ',', $$hosts; - my @threads = Loadbars::Main::create_threads @hosts; - Loadbars::Main::main_loop $dispatch, @threads; +if ( @hosts || defined $Loadbars::Main::C{cluster} ) { + push @hosts, Loadbars::Config::get_cluster_hosts $C{cluster} + if defined $C{cluster}; + system 'ssh-add'; - exit Loadbars::Constants->SUCCESS; } +else { + Loadbars::Main::say $dispatch->('usage'); + exit Loadbars::Constants->E_NOHOST; +} + +my @threads = Loadbars::Main::create_threads @hosts; +Loadbars::Main::loop $dispatch, @threads; -main; +exit Loadbars::Constants->SUCCESS; -1; |
