Show
Ignore:
Timestamp:
12/28/07 11:23:43 (13 months ago)
Author:
tokuhirom
Message:

r3655@mnk (orig r305): tokuhiro | 2007-03-05 21:15:35 -0800
perltidied.


Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Archer/lib/Archer/Shell.pm

    r3701 r3702  
    99    my ( $class, $args ) = @_; 
    1010 
    11     return bless { %$args }, $class; 
     11    return bless {%$args}, $class; 
    1212} 
    1313 
    1414sub run_loop { 
    15     my ($self, ) = @_; 
     15    my ( $self, ) = @_; 
    1616 
    1717    my $term = Term::ReadLine->new('Archer'); 
    1818 
    19     my $HISTFILE = ($ENV{HOME} || ((getpwuid($<))[7])) . "/.archer_shell_history"; 
     19    my $HISTFILE = ( $ENV{HOME} || ( ( getpwuid($<) )[7] ) ) 
     20        . "/.archer_shell_history"; 
    2021    my $HISTSIZE = 256; 
    2122 
    2223   # this won't work with Term::ReadLine::Perl 
    2324   # If there is Term::ReadLine::Gnu, be sure to do : export "PERL_RL=Gnu o=0" 
    24     eval { $term->stifle_history( $HISTSIZE ); }; 
    25  
    26     if ( @! ) { 
    27         $self->{ context }->log( 'debug' => "You will need Term::ReadLine::Gnu" ); 
    28     } else { 
     25    eval { $term->stifle_history($HISTSIZE); }; 
     26 
     27    if (@!) { 
     28        $self->{context} 
     29            ->log( 'debug' => "You will need Term::ReadLine::Gnu" ); 
     30    } 
     31    else { 
    2932        if ( -f $HISTFILE ) { 
    30             $term->ReadHistory( $HISTFILE ) 
    31                 or $self->{ context }->log( 'warn' => "cannot read history file: $!" ); 
    32         } 
    33     } 
    34  
    35     while ( defined( my $line = $term->readline( 'archer> ' ) ) ) { 
     33            $term->ReadHistory($HISTFILE) 
     34                or $self->{context} 
     35                ->log( 'warn' => "cannot read history file: $!" ); 
     36        } 
     37    } 
     38 
     39    while ( defined( my $line = $term->readline('archer> ') ) ) { 
    3640        next if $line =~ /^\s*$/; 
    37         $self->catch_run( $line ); 
     41        $self->catch_run($line); 
    3842    } 
    3943 
    4044    print "\n"; 
    4145 
    42     eval { $term->WriteHistory( $HISTFILE ); }; 
    43     if ( @! ) { 
    44         $self->{context}->log( 'debug' => "perlsh: cannot write history file: $!" ); 
     46    eval { $term->WriteHistory($HISTFILE); }; 
     47    if (@!) { 
     48        $self->{context} 
     49            ->log( 'debug' => "perlsh: cannot write history file: $!" ); 
    4550    } 
    4651 
     
    5055    my ( $self, $cmd ) = @_; 
    5156 
    52     $self->{ parallel } 
    53         = $self->{ context }->{ config }->{ global }->{ parallel } 
     57    $self->{parallel} = $self->{context}->{config}->{global}->{parallel} 
    5458        || 'Archer::Parallel::ForkManager'; 
    55     $self->{ parallel }->use or die $@; 
     59    $self->{parallel}->use or die $@; 
    5660 
    5761    if ( $cmd =~ /^on/ ) { 
    5862        if ( $cmd =~ /^on\s(.*)\sdo\s(.*)$/ ) { 
    5963            $self->process_host( $1, $2 ); 
    60         } else { 
     64        } 
     65        else { 
    6166            print "[WARNING] error in your syntax, see help\n"; 
    6267        } 
    63     } elsif ( $cmd =~ /^with/ ) { 
     68    } 
     69    elsif ( $cmd =~ /^with/ ) { 
    6470        if ( $cmd =~ /^with\s(.*)\sdo\s(.*)$/ ) { 
    6571            $self->process_role( $1, $2 ); 
    66         } else { 
     72        } 
     73        else { 
    6774            print "[WARNING] error in your syntax, see help\n"; 
    6875        } 
    69     } elsif ( $cmd =~ /^help/ ) { 
     76    } 
     77    elsif ( $cmd =~ /^help/ ) { 
    7078        $self->help(); 
    71     } elsif ( $cmd =~ /^(quit|exit)/ ) { 
     79    } 
     80    elsif ( $cmd =~ /^(quit|exit)/ ) { 
    7281        print "bye bye\n"; 
    7382        exit; 
    74     } elsif ( $cmd =~ /^!/ ) { 
     83    } 
     84    elsif ( $cmd =~ /^!/ ) { 
    7585        if ( $cmd =~ /^!(\w+)\s?(on|with)?\s?(.*)?$/ ) { 
    7686            my $task     = $1; 
    7787            my $action   = $2; 
    7888            my $machines = $3; 
    79             if (    defined $action 
    80                  && defined $machines 
    81                  && length( $machines ) < 1 ) 
     89            if (   defined $action 
     90                && defined $machines 
     91                && length($machines) < 1 ) 
    8292            { 
    8393                return print "[WARNING] error in your syntax, see help\n"; 
    8494            } 
    8595            my $executed = 0; 
    86             for 
    87                 my $plugin ( @{ $self->{ config }->{ tasks }->{ process } } ) 
    88             { 
    89                 next if $plugin->{ name } ne $task; 
     96            for my $plugin ( @{ $self->{config}->{tasks}->{process} } ) { 
     97                next if $plugin->{name} ne $task; 
    9098                $executed = 1; 
    9199                if ( defined $action ) { 
    92100                    if ( $action eq "on" ) { 
    93101                        my @hosts = split " ", $machines; 
    94                         for my $host ( @hosts ) { 
     102                        for my $host (@hosts) { 
    95103                            $self->process_task( $plugin, $host ); 
    96104                        } 
    97                     } else { 
     105                    } 
     106                    else { 
    98107                        my @roles = split " ", $machines; 
    99                         for my $role ( @roles ) { 
    100                             for my $host ( 
    101                                           @{ $self->{ servers }->{ $role } } ) 
    102                             { 
     108                        for my $role (@roles) { 
     109                            for my $host ( @{ $self->{servers}->{$role} } ) { 
    103110                                $self->process_task( $plugin, $host ); 
    104111                            } 
    105112                        } 
    106113                    } 
    107                 } else { 
     114                } 
     115                else { 
    108116                    for my $host ( 
    109                                    @{  $self->{ servers } 
    110                                            ->{ $plugin->{ config }->{ role } } 
    111                                    } ) 
     117                        @{ $self->{servers}->{ $plugin->{config}->{role} } } ) 
    112118                    { 
    113119                        $self->process_task( $plugin, $host ); 
     
    118124                print "[WARNING] unable to find the requested task: $task\n"; 
    119125            } 
    120         } else { 
     126        } 
     127        else { 
    121128            print "[WARNING] error in your syntax\n"; 
    122129        } 
    123     } else { 
    124         $self->process_command( $cmd ); 
     130    } 
     131    else { 
     132        $self->process_command($cmd); 
    125133    } 
    126134} 
     
    132140 
    133141    # check if hosts are in our config. 
    134     for my $host ( @hosts ) { 
    135         for my $role ( keys %{ $self->{ servers } } ) { 
    136             @hosts = grep ( /$host/, @{ $self->{ servers }->{ $role } } ); 
    137         } 
    138     } 
    139  
    140     if ( @hosts ) { 
     142    for my $host (@hosts) { 
     143        for my $role ( keys %{ $self->{servers} } ) { 
     144            @hosts = grep ( /$host/, @{ $self->{servers}->{$role} } ); 
     145        } 
     146    } 
     147 
     148    if (@hosts) { 
    141149        $self->process_command( $cmd, \@hosts ); 
    142150    } 
     
    149157    my @hosts      = (); 
    150158    my @inexistant = (); 
    151     for my $role ( @roles ) { 
    152         if ( !defined $self->{ servers }->{ $role } ) { 
     159    for my $role (@roles) { 
     160        if ( !defined $self->{servers}->{$role} ) { 
    153161            push( @inexistant, $role ); 
    154162            next; 
    155163        } 
    156         for my $host ( @{ $self->{ servers }->{ $role } } ) { 
     164        for my $host ( @{ $self->{servers}->{$role} } ) { 
    157165            push @hosts, $host; 
    158166        } 
    159167    } 
    160     if ( @inexistant ) { 
     168    if (@inexistant) { 
    161169        print "[WARNING] inexisting role(s) for " 
    162170            . join( ' ', @inexistant ) . "\n"; 
     
    201209    my $class = "Archer::Plugin::$plugin->{module}"; 
    202210    $class->use or die $@; 
    203     $class->new( { config  => $plugin->{ config }, 
    204                    project => $self->{ context }->{ project }, 
    205                    server  => $host 
    206                  } )->run( $self->{ context } ); 
     211    $class->new( 
     212        {   config  => $plugin->{config}, 
     213            project => $self->{context}->{project}, 
     214            server  => $host 
     215        } 
     216    )->run( $self->{context} ); 
    207217} 
    208218 
     
    220230 
    221231sub help { 
    222     my ( $self ) = @_; 
     232    my ($self) = @_; 
    223233    my $help = <<HELP; 
    224234 To quit, just type quit, exit, or press ctrl-D.