mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-16 16:23:30 +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:
|
# Checks whenever said filehandle is open. If it's not, defaults to STDOUT.
|
||||||
# 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.
|
|
||||||
|
|
||||||
sub out_fh {
|
sub out_fh {
|
||||||
my ( $self, $new_fh ) = @_;
|
my ( $self ) = @_;
|
||||||
|
|
||||||
# ->opened comes from IO::Handle.
|
|
||||||
if ( $new_fh && ref($new_fh) && $new_fh->opened ) {
|
|
||||||
$self->{out_fh} = $new_fh;
|
|
||||||
}
|
|
||||||
if ( !$self->{out_fh} || !$self->{out_fh}->opened ) {
|
if ( !$self->{out_fh} || !$self->{out_fh}->opened ) {
|
||||||
$self->{out_fh} = \*STDOUT;
|
$self->{out_fh} = \*STDOUT;
|
||||||
}
|
}
|
||||||
return $self->{out_fh};
|
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 {
|
sub column_regex {
|
||||||
my ( $self, $new_re ) = @_;
|
my ( $self, $new_re ) = @_;
|
||||||
if ($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");
|
is($obj->out_fh(), \*STDOUT, "by default, outputs to STDOUT");
|
||||||
open my $fh, "<", \my $tmp;
|
open my $fh, "<", \my $tmp;
|
||||||
$obj->out_fh($fh);
|
$obj->set_out_fh($fh);
|
||||||
is($obj->out_fh(), $fh, "Changing it works");
|
is($obj->out_fh(), $fh, "Changing it works");
|
||||||
close($fh);
|
close($fh);
|
||||||
is($obj->out_fh(), \*STDOUT, "and if we close the set filehandle, it reverts to STDOUT");
|
is($obj->out_fh(), \*STDOUT, "and if we close the set filehandle, it reverts to STDOUT");
|
||||||
|
Reference in New Issue
Block a user