mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-16 00:03:02 +00:00
Explicit setter for out_fh.
This commit is contained in:
@@ -156,24 +156,26 @@ sub set_interactive {
|
||||
}
|
||||
}
|
||||
|
||||
# What this method does is thee-fold:
|
||||
# It sets or returns the currently set filehandle, kind of like a poor man's
|
||||
# select(); but also, it checks whenever said filehandle is open. If it's not,
|
||||
# it defaults to STDOUT.
|
||||
|
||||
# Checks whenever said filehandle is open. If it's not, defaults to STDOUT.
|
||||
sub out_fh {
|
||||
my ( $self, $new_fh ) = @_;
|
||||
|
||||
# ->opened comes from IO::Handle.
|
||||
if ( $new_fh && ref($new_fh) && $new_fh->opened ) {
|
||||
$self->{out_fh} = $new_fh;
|
||||
}
|
||||
my ( $self ) = @_;
|
||||
if ( !$self->{out_fh} || !$self->{out_fh}->opened ) {
|
||||
$self->{out_fh} = \*STDOUT;
|
||||
}
|
||||
return $self->{out_fh};
|
||||
}
|
||||
|
||||
# It sets or returns the currently set filehandle, kind of like a poor man's
|
||||
# select().
|
||||
sub set_out_fh {
|
||||
my ( $self, $new_fh ) = @_;
|
||||
# ->opened comes from IO::Handle.
|
||||
if ( $new_fh && ref($new_fh) && $new_fh->opened ) {
|
||||
$self->{out_fh} = $new_fh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub column_regex {
|
||||
my ( $self, $new_re ) = @_;
|
||||
if ($new_re) {
|
||||
|
@@ -182,7 +182,7 @@ for my $method ( qw( curr_ts prev_ts first_ts ) ) {
|
||||
|
||||
is($obj->out_fh(), \*STDOUT, "by default, outputs to STDOUT");
|
||||
open my $fh, "<", \my $tmp;
|
||||
$obj->out_fh($fh);
|
||||
$obj->set_out_fh($fh);
|
||||
is($obj->out_fh(), $fh, "Changing it works");
|
||||
close($fh);
|
||||
is($obj->out_fh(), \*STDOUT, "and if we close the set filehandle, it reverts to STDOUT");
|
||||
|
Reference in New Issue
Block a user