Ensure code is run through 'perltidy -pbp -nst -nse'

This commit is contained in:
Duncan Ferguson 2014-09-19 23:33:08 +01:00
parent d9446aa28a
commit f8ed9da353
13 changed files with 184 additions and 156 deletions

View file

@ -83,15 +83,14 @@ my $build = $class->new(
'Test::Differences' => 0, 'Test::Differences' => 0,
'CPAN::Changes' => 0.27, 'CPAN::Changes' => 0.27,
'File::Slurp' => 0, 'File::Slurp' => 0,
'Test::PerlTidy' => 0,
}, },
configure_requires => { 'Module::Build' => 0, }, configure_requires => { 'Module::Build' => 0, },
add_to_cleanup => ['App-ClusterSSH-*'], add_to_cleanup => ['App-ClusterSSH-*'],
create_makefile_pl => 'traditional', create_makefile_pl => 'traditional',
script_files => 'bin', script_files => 'bin',
get_options => { changes => { type => '=s' }, }, get_options => { changes => { type => '=s' }, },
PL_files => { PL_files => { 'bin_PL/_build_docs' => [], },
'bin_PL/_build_docs' => [],
},
); );
$build->create_build_script; $build->create_build_script;

View file

@ -46,5 +46,7 @@ t/external_cluster_command
THANKS THANKS
t/manifest.t t/manifest.t
TODO TODO
t/perltidy.t
t/perltidyrc
t/pod-coverage.t t/pod-coverage.t
t/pod.t t/pod.t

View file

@ -1,7 +1,6 @@
# Note: this file was auto-generated by Module::Build::Compat version 0.4003 # Note: this file was auto-generated by Module::Build::Compat version 0.4003
use ExtUtils::MakeMaker; use ExtUtils::MakeMaker;
WriteMakefile WriteMakefile(
(
'NAME' => 'App::ClusterSSH', 'NAME' => 'App::ClusterSSH',
'VERSION_FROM' => 'lib/App/ClusterSSH.pm', 'VERSION_FROM' => 'lib/App/ClusterSSH.pm',
'PREREQ_PM' => { 'PREREQ_PM' => {
@ -23,14 +22,6 @@ WriteMakefile
'version' => '0' 'version' => '0'
}, },
'INSTALLDIRS' => 'site', 'INSTALLDIRS' => 'site',
'EXE_FILES' => [ 'EXE_FILES' => [ 'bin/ccon', 'bin/crsh', 'bin/cssh', 'bin/ctel' ],
'bin/ccon', 'PL_FILES' => { 'bin_PL/_build_docs' => [] }
'bin/crsh', );
'bin/cssh',
'bin/ctel'
],
'PL_FILES' => {
'bin_PL/_build_docs' => []
}
)
;

View file

@ -1881,8 +1881,8 @@ sub populate_send_menu {
-label => 'Random Number', -label => 'Random Number',
-command => sub { -command => sub {
$self->send_variable_text_to_all_servers( $self->send_variable_text_to_all_servers(
sub { int(rand(1024)) } sub { int( rand(1024) ) } ),
), ;
}, },
); );
} }

View file

@ -52,8 +52,7 @@ sub list_external_clusters {
my ( $self, ) = @_; my ( $self, ) = @_;
my @list = $self->_run_external_clusters('-L'); my @list = $self->_run_external_clusters('-L');
return return wantarray
wantarray
? sort @list ? sort @list
: scalar @list; : scalar @list;
} }
@ -70,7 +69,11 @@ sub _run_external_clusters {
my $external_command = $self->parent->config->{external_cluster_command}; my $external_command = $self->parent->config->{external_cluster_command};
if ( !$external_command || !-x $external_command ) { if ( !$external_command || !-x $external_command ) {
$self->debug( 1, 'Cannot run external cluster command: ', $external_command || ''); $self->debug(
1,
'Cannot run external cluster command: ',
$external_command || ''
);
return; return;
} }
@ -184,8 +187,7 @@ sub get_tag {
join( ' ', sort @{ $self->{tags}->{$tag} } ) join( ' ', sort @{ $self->{tags}->{$tag} } )
); );
return return wantarray
wantarray
? sort @{ $self->{tags}->{$tag} } ? sort @{ $self->{tags}->{$tag} }
: scalar @{ $self->{tags}->{$tag} }; : scalar @{ $self->{tags}->{$tag} };
} }
@ -196,8 +198,7 @@ sub get_tag {
sub list_tags { sub list_tags {
my ($self) = @_; my ($self) = @_;
return return wantarray
wantarray
? sort keys( %{ $self->{tags} } ) ? sort keys( %{ $self->{tags} } )
: scalar keys( %{ $self->{tags} } ); : scalar keys( %{ $self->{tags} } );
} }

View file

@ -212,7 +212,9 @@ sub add_common_options {
); );
$self->add_option( $self->add_option(
spec => 'unique-servers|u', spec => 'unique-servers|u',
help => $self->loc('Toggle connecting to each host only once when a hostname has been specified multiple times.'), help => $self->loc(
'Toggle connecting to each host only once when a hostname has been specified multiple times.'
),
); );
$self->add_option( $self->add_option(
spec => 'use-all-a-records|A', spec => 'use-all-a-records|A',
@ -302,6 +304,7 @@ sub getopts {
no warnings 'redefine'; no warnings 'redefine';
*$accessor = sub { *$accessor = sub {
return $options->{$acc} || $default; return $options->{$acc} || $default;
# defined $options->{$acc} ? $options->{$acc} # defined $options->{$acc} ? $options->{$acc}
# : defined $self->{command_options}->{$acc}->{default} # : defined $self->{command_options}->{$acc}->{default}
# ? $self->{command_options}->{$acc}->{default} # ? $self->{command_options}->{$acc}->{default}
@ -395,7 +398,8 @@ This tool is intended for (but not limited to) cluster administration where the
Connections are opened using [_1] which must be correctly installed and configured. Connections are opened using [_1] which must be correctly installed and configured.
Extra caution should be taken when editing files as lines may not necessarily be in the same order; assuming line 5 is the same across all servers and modifying that is dangerous. It's better to search for the specific line to be changed and double-check all terminals are as expected before changes are committed.}, $self->parent->config->{comms} Extra caution should be taken when editing files as lines may not necessarily be in the same order; assuming line 5 is the same across all servers and modifying that is dangerous. It's better to search for the specific line to be changed and double-check all terminals are as expected before changes are committed.},
$self->parent->config->{comms}
); );
output '=head2 ', $self->loc('Further Notes'); output '=head2 ', $self->loc('Further Notes');
@ -431,7 +435,8 @@ Extra caution should be taken when editing files as lines may not necessarily be
[_1] [_1]
This will test the mechanisms used to open windows to hosts. This could be due to either the [_2] terminal option which enables [_3] (some terminals do not require this option, other terminals have another method for enabling it - see your terminal documentation) or the configuration of [_4].}, This will test the mechanisms used to open windows to hosts. This could be due to either the [_2] terminal option which enables [_3] (some terminals do not require this option, other terminals have another method for enabling it - see your terminal documentation) or the configuration of [_4].},
"C<< $Script -e {single host name} >>", 'C<-xrm>', 'C<AllowSendEvents>', "C<< $Script -e {single host name} >>", 'C<-xrm>',
'C<AllowSendEvents>',
'C<' . $self->parent->config->{comms} . '>', 'C<' . $self->parent->config->{comms} . '>',
); );
output '=back'; output '=back';
@ -490,17 +495,14 @@ would replace the <Alt-n> with the client's name in each window.}
); );
output '=item ', $self->parent->config->{key_localname}; output '=item ', $self->parent->config->{key_localname};
output $self->loc( output $self->loc(
q{Paste in the hostname of the server cssh is ebing run on} q{Paste in the hostname of the server cssh is ebing run on});
);
output '=item ', $self->parent->config->{key_quit}; output '=item ', $self->parent->config->{key_quit};
output $self->loc( output $self->loc(
'Quit the program and close all connections and windows.'); 'Quit the program and close all connections and windows.');
output '=item ', $self->parent->config->{key_retilehosts}; output '=item ', $self->parent->config->{key_retilehosts};
output $self->loc(q{Retile all the client windows.}); output $self->loc(q{Retile all the client windows.});
output '=item ', $self->parent->config->{key_username}; output '=item ', $self->parent->config->{key_username};
output $self->loc( output $self->loc(q{Paste in the username for the connection});
q{Paste in the username for the connection}
);
output '=back'; output '=back';
output '=head1 ' . $self->loc('EXAMPLES'); output '=head1 ' . $self->loc('EXAMPLES');
@ -521,7 +523,8 @@ would replace the <Alt-n> with the client's name in each window.}
$self->loc( $self->loc(
q{Open up a cluster defined in a non-default configuration file}); q{Open up a cluster defined in a non-default configuration file});
output q{S<$ } . $Script . q{ -c $HOME/cssh.extra_clusters db_cluster>}; output q{S<$ } . $Script . q{ -c $HOME/cssh.extra_clusters db_cluster>};
output '=item ', $self->loc(q{Connect on port 2022 instead of the default port}); output '=item ',
$self->loc(q{Connect on port 2022 instead of the default port});
output q{S<$ } . $Script . q{ -p 2022 server1 server2>}; output q{S<$ } . $Script . q{ -p 2022 server1 server2>};
output '=back'; output '=back';
@ -796,9 +799,7 @@ B<NOTE:> Any "generic" change to the method (e.g., specifying the ssh port to us
); );
output '=item use_hotkeys = 1'; output '=item use_hotkeys = 1';
output $self->loc( output $self->loc( q{Setting to [_1] will disable all hotkeys.}, 'C<0>' );
q{Setting to [_1] will disable all hotkeys.},
'C<0>' );
output '=item user = $LOGNAME'; output '=item user = $LOGNAME';
output $self->loc( output $self->loc(
@ -912,7 +913,8 @@ B<NOTE:> Any "generic" change to the method (e.g., specifying the ssh port to us
[_2] [_2]
This performs two tests to confirm cssh is able to work properly with the settings provided within the [_3] file (or internal defaults). This performs two tests to confirm cssh is able to work properly with the settings provided within the [_3] file (or internal defaults).
}, $Script, 'C<< '.$Script.' -e [user@]<hostname>[:port] >>', 'F<$HOME/.clusterssh/config>' }, $Script, 'C<< ' . $Script . ' -e [user@]<hostname>[:port] >>',
'F<$HOME/.clusterssh/config>'
); );
output '=over'; output '=over';
@ -921,7 +923,8 @@ This performs two tests to confirm cssh is able to work properly with the settin
q{Test the terminal window works with the options provided}); q{Test the terminal window works with the options provided});
output '=item 2'; output '=item 2';
output $self->loc( output $self->loc(
q{Test [_1] works to a host with the configured arguments}, $self->parent->config->{comms}); q{Test [_1] works to a host with the configured arguments},
$self->parent->config->{comms} );
output '=back'; output '=back';
output $self->loc(q{Configuration options to watch for in ssh are}); output $self->loc(q{Configuration options to watch for in ssh are});

View file

@ -22,7 +22,10 @@ sub new {
sub script { sub script {
my ( $self, $config ) = @_; my ( $self, $config ) = @_;
if(! defined $config || ! ref $config || ref $config ne "App::ClusterSSH::Config") { if ( !defined $config
|| !ref $config
|| ref $config ne "App::ClusterSSH::Config" )
{
croak( croak(
App::ClusterSSH::Exception::Helper->throw( App::ClusterSSH::Exception::Helper->throw(
error => 'No configuration provided or in wrong format', error => 'No configuration provided or in wrong format',
@ -30,8 +33,9 @@ sub script {
); );
} }
foreach my $arg ( "comms", $config->{comms}, $config->{comms} . '_args', 'command', 'auto_close' foreach my $arg ( "comms", $config->{comms}, $config->{comms} . '_args',
) { 'command', 'auto_close' )
{
if ( !defined $config->{$arg} ) { if ( !defined $config->{$arg} ) {
croak( croak(
App::ClusterSSH::Exception::Helper->throw( App::ClusterSSH::Exception::Helper->throw(

View file

@ -165,7 +165,10 @@ sub parse_host_string {
{ {
$self->debug( $self->debug(
5, 5,
$self->loc( 'bracketed IPv6: u=[_1] h=[_2] p=[_3] g=[_4]', $1, $2, $3, $4 ), $self->loc(
'bracketed IPv6: u=[_1] h=[_2] p=[_3] g=[_4]',
$1, $2, $3, $4
),
); );
return __PACKAGE__->new( return __PACKAGE__->new(
parse_string => $parse_string, parse_string => $parse_string,
@ -188,8 +191,12 @@ sub parse_host_string {
}xms }xms
) )
{ {
$self->debug( 5, $self->debug(
$self->loc( 'std IPv4: u=[_1] h=[_2] p=[_3] g=[_4]', $1, $2, $3, $4 ), 5,
$self->loc(
'std IPv4: u=[_1] h=[_2] p=[_3] g=[_4]',
$1, $2, $3, $4
),
); );
return __PACKAGE__->new( return __PACKAGE__->new(
parse_string => $parse_string, parse_string => $parse_string,
@ -251,8 +258,7 @@ sub parse_host_string {
); );
} }
if ( $colon_count > 1 if ( $colon_count > 1
&& $colon_count < 8 && $colon_count < 8 )
)
{ {
warn 'Ambiguous host string: "', $host_string, '"', $/; warn 'Ambiguous host string: "', $host_string, '"', $/;
warn 'Assuming you meant "[', $host_string, ']"?', $/; warn 'Assuming you meant "[', $host_string, ']"?', $/;
@ -260,8 +266,8 @@ sub parse_host_string {
$self->debug( $self->debug(
5, 5,
$self->loc( $self->loc(
'Ambiguous IPv6 u=[_1] h=[_2] p=[_3] g=[_4]', $username, 'Ambiguous IPv6 u=[_1] h=[_2] p=[_3] g=[_4]',
$host_string, $port, $geometry, $username, $host_string, $port, $geometry,
) )
); );

View file

@ -668,12 +668,9 @@ my %parse_tests = (
geometry => q{}, geometry => q{},
type => 'ipv6', type => 'ipv6',
}, },
'2001:0db8:8a2e:0370:7334:2001:0db8:8a2e:0370:7334:4535:3453:3453:3455' => { '2001:0db8:8a2e:0370:7334:2001:0db8:8a2e:0370:7334:4535:3453:3453:3455'
die => qr{Unable to parse hostname from}ms, => { die => qr{Unable to parse hostname from}ms, },
}, 'some random rubbish' => { die => qr{Unable to parse hostname from}ms, },
'some random rubbish' => {
die => qr{Unable to parse hostname from}ms,
},
); );
foreach my $ident ( keys(%parse_tests) ) { foreach my $ident ( keys(%parse_tests) ) {
@ -684,12 +681,19 @@ foreach my $ident ( keys(%parse_tests) ) {
if ( $parse_tests{$ident}{die} ) { if ( $parse_tests{$ident}{die} ) {
is( $trap->leaveby, 'die', $ident . ' died correctly' ); is( $trap->leaveby, 'die', $ident . ' died correctly' );
like( $trap->die, $parse_tests{$ident}{die}, $ident . ' died correctly' ); like(
$trap->die,
$parse_tests{$ident}{die},
$ident . ' died correctly'
);
next; next;
} }
is( $trap->leaveby, 'return', $ident . ' returned correctly' ); is( $trap->leaveby, 'return', $ident . ' returned correctly' );
is( $host, $parse_tests{$ident}{hostname}, 'stringify works on: '.$ident ); is( $host,
$parse_tests{$ident}{hostname},
'stringify works on: ' . $ident
);
isa_ok( $host, "App::ClusterSSH::Host" ); isa_ok( $host, "App::ClusterSSH::Host" );
@ -699,8 +703,10 @@ foreach my $ident ( keys(%parse_tests) ) {
$parse_tests{$ident}{$trap_type}, $parse_tests{$ident}{$trap_type},
"$ident $trap_type" "$ident $trap_type"
); );
} else { }
like( $trap->$trap_type, else {
like(
$trap->$trap_type,
$parse_tests{$ident}{$trap_type}, $parse_tests{$ident}{$trap_type},
"$ident $trap_type" "$ident $trap_type"
); );
@ -725,7 +731,6 @@ foreach my $ident ( keys(%parse_tests) ) {
is( $host->check_ssh_hostname, 0, $ident . ' not from ssh' ); is( $host->check_ssh_hostname, 0, $ident . ' not from ssh' );
} }
# check for a non-existant file # check for a non-existant file
trap { trap {
$host = App::ClusterSSH::Host->new( $host = App::ClusterSSH::Host->new(

View file

@ -109,7 +109,8 @@ $expected{tag20} = [ 'host10', ];
$expected{tag30} = [ 'host10', ]; $expected{tag30} = [ 'host10', ];
$expected{tag40} = [ 'host20', 'host30', ]; $expected{tag40} = [ 'host20', 'host30', ];
$expected{tag50} = [ 'host30', ]; $expected{tag50} = [ 'host30', ];
$cluster1->read_tag_file( $Bin . '/30cluster.tag1' ); test_expected( 'tag 1', %expected ); $cluster1->read_tag_file( $Bin . '/30cluster.tag1' );
test_expected( 'tag 1', %expected );
$cluster1->read_cluster_file( $Bin . '/30cluster.file3' ); $cluster1->read_cluster_file( $Bin . '/30cluster.file3' );
my @default_expected = (qw/ host7 host8 host9 /); my @default_expected = (qw/ host7 host8 host9 /);
@ -165,10 +166,9 @@ is( $trap->stdout, '', 'no stdout for non-existant get_tag' );
is( $trap->stderr, '', 'no stderr for non-existant get_tag' ); is( $trap->stderr, '', 'no stderr for non-existant get_tag' );
is( $tags, undef, 'non-existant tag returns undef' ); is( $tags, undef, 'non-existant tag returns undef' );
@external_expected = $cluster1->list_external_clusters(); @external_expected = $cluster1->list_external_clusters();
is_deeply( \@external_expected, [], is_deeply( \@external_expected, [], 'External command doesnt exist' );
'External command doesnt exist' is( scalar $cluster1->list_external_clusters,
); 0, 'External command failed tag count' );
is( scalar $cluster1->list_external_clusters, 0, 'External command failed tag count');
$mock_object->{external_cluster_command} = "$Bin/external_cluster_command"; $mock_object->{external_cluster_command} = "$Bin/external_cluster_command";
@ -178,7 +178,8 @@ is_deeply(
[qw/ tag100 tag200 tag300 tag400 /], [qw/ tag100 tag200 tag300 tag400 /],
'External command no args' 'External command no args'
); );
is( scalar $cluster1->list_external_clusters, 4, 'External command tag count'); is( scalar $cluster1->list_external_clusters,
4, 'External command tag count' );
@external_expected = $cluster1->get_external_clusters(); @external_expected = $cluster1->get_external_clusters();
is_deeply( \@external_expected, [], 'External command no args' ); is_deeply( \@external_expected, [], 'External command no args' );

16
t/perltidy.t Normal file
View file

@ -0,0 +1,16 @@
#!perl -T
use strict;
use warnings;
use Test::More;
use FindBin qw($Bin);
eval "use Test::PerlTidy";
plan skip_all => "Test::PerlTidy required for testing code" if $@;
# Please see t/perltidyrc for the authors normal perltidy options
run_tests(
perltidyrc => $Bin . '/perltidyrc',
exclude => [ '_build/', 'blib/' ]
);