Fix a logic bug around --debug option handling

the Base.pm debug method was being overridden within Getopt.pm when all
command line options are turned into accessors.  Since this is done on the
fly there is no compiler warning generated for it.

Also renamed a method in base from 'output' to 'stdout_output' as two objects
had the same method name - Getopt::output and Base::output
This commit is contained in:
Duncan Ferguson 2017-03-03 22:52:32 +00:00
parent 4fe7b00713
commit 41fe0714b5
4 changed files with 13 additions and 8 deletions

View file

@ -1,5 +1,6 @@
4.09 0000-00-00 Duncan Ferguson <duncan_ferguson@user.sf.net>
- Add perl-5.24 Travis-CI automated testing config
- Correct a logic bug around the --debug option
4.08 2016-10-18 Duncan Ferguson <duncan_ferguson@user.sf.net>
- Add perl-5.8, 5.10 and 5.12 to Travis-CI automated testing

View file

@ -112,7 +112,7 @@ sub debug_level {
return $debug_level;
}
sub output {
sub stdout_output {
my ( $self, @text ) = @_;
print @text, $/;
return $self;
@ -121,7 +121,7 @@ sub output {
sub debug {
my ( $self, $level, @text ) = @_;
if ( $level <= $debug_level ) {
$self->output(@text);
$self->stdout_output(@text);
}
return $self;
}
@ -335,7 +335,7 @@ Using the App::ClusterSSH/L10N/{lang}.pm module convert the given text to
appropriate language. See L<App::ClusterSSH::L10N> for more details. Essentially
a wrapper to maketext in Locale::Maketext
=item $obj->output(@);
=item $obj->stdout_output(@);
Output text on STDOUT.

View file

@ -18,7 +18,7 @@ sub new {
my ( $class, %args ) = @_;
# basic setup that is over-rideable by each script as needs may be
# different depending ont he command used
# different depending on the command used
my %setup = (
usage => [
'-h|--help', '[options] [[user@]<server>[:port]|<tag>] [...] ',
@ -126,7 +126,7 @@ sub add_common_options {
$self->add_option(
spec => 'debug:+',
help => $self->loc(
"Enable debugging. Either a level can be provided or the option can be repeated multiple times. Maximum level is 4."
"Enable debugging. Either a level can be provided or the option can be repeated multiple times. Maximum level is 9."
),
default => 0,
);
@ -306,10 +306,14 @@ sub getopts {
}
$options->{debug} ||= 0;
$options->{debug} = 4 if ( $options->{debug} && $options->{debug} > 4 );
$options->{debug} = 9 if ( $options->{debug} && $options->{debug} > 9 );
# Now all options are set to the correct values, generate accessor methods
foreach my $option ( sort keys( %{ $self->{command_options} } ) ) {
# skip some accessors as they are already defined elsewhere
next if $option =~ m/^(debug)\W/;
my $accessor = $self->{command_options}->{$option}->{accessor};
my $default = $self->{command_options}->{$option}->{default};
@ -333,7 +337,7 @@ sub getopts {
}
}
$self->set_debug_level( $self->debug );
$self->set_debug_level( $options->{debug} );
$self->parent->config->load_configs( $self->config_file );

View file

@ -19,7 +19,7 @@ isa_ok( $base, 'App::ClusterSSH::Base' );
diag('testing output') if ( $ENV{TEST_VERBOSE} );
trap {
$base->output('testing');
$base->stdout_output('testing');
};
is( $trap->leaveby, 'return', 'returned ok' );
is( $trap->die, undef, 'returned ok' );