Skip to content

Commit

Permalink
Item14205: Change to the new Aux::MuteOut module
Browse files Browse the repository at this point in the history
Thanks to VadimBelman for the new capture module
  • Loading branch information
gac410 committed Nov 14, 2016
1 parent d857659 commit 27821cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 76 deletions.
81 changes: 5 additions & 76 deletions core/lib/Foswiki/Configure/Wizards/AutoConfigureEmail.pm
@@ -1,77 +1,4 @@
# See bottom of file for license and copyright information
package Foswiki::Configure::Wizards::AutoConfigureEmail::MuteOut;
use strict;
use warnings;
use File::Temp;
use File::Spec;

sub new {
my $class = shift;
my %params = @_;

$class = ref($class) || $class;

my ( $oldOut, $oldErr, $rc );

my $outFile = $params{outFile} || File::Spec->devnull;
my $errFile = $params{errFile} || File::Spec->devnull;
my $reporter = $params{reporter};

unless ( open $oldOut, ">&", STDOUT ) {
$reporter->ERROR( "Cannot dup STDOUT: " . $! );
return undef;
}
unless ( open $oldErr, ">&", STDERR ) {
$reporter->ERROR( "Cannot dup STDERR: " . $! );
return undef;
}
unless ( open STDOUT, ">", $outFile ) {
$reporter->ERROR( "Failed to redirect STDOUT: " . $! );
}
unless ( open STDERR, ">", $errFile ) {
$reporter->ERROR( "Failed to redirect STDERR: " . $! );
}

my $obj = bless {
oldOut => $oldOut,
oldErr => $oldErr,
outFile => $outFile,
errFile => $errFile,
reporter => $reporter,
}, $class;

return $obj;
}

sub exec {
my $this = shift;
my ($sub) = shift;

my @rc;
my $wantarray = wantarray;
if ($wantarray) {
@rc = $sub->(@_);
}
elsif ( defined $wantarray ) {
$rc[0] = $sub->(@_);
}
else {
$sub->(@_);
}

return $wantarray ? @rc : $rc[0];
}

sub DESTROY {
my $this = shift;

unless ( open STDOUT, ">&", $this->{oldOut} ) {
$this->reporter->ERROR( "Failed to restore STDOUT: " . $! );
}
unless ( open STDERR, ">&", $this->{oldErr} ) {
$this->reporter->ERROR( "Failed to restore STDOUT: " . $! );
}
}

package Foswiki::Configure::Wizards::AutoConfigureEmail;

Expand All @@ -87,6 +14,9 @@ use strict;
use warnings;

use Foswiki::Configure::Wizard ();
use Foswiki::Aux::MuteOut ();
use File::Temp ();

our @ISA = ('Foswiki::Configure::Wizard');

use constant DEBUG_SSL => 1;
Expand Down Expand Up @@ -183,12 +113,11 @@ sub _muteExec {
close $fh2;

{
my $muter =
Foswiki::Configure::Wizards::AutoConfigureEmail::MuteOut->new(
my $muter = Foswiki::Aux::MuteOut->new(
outFile => $outFile,
errFile => $errFile,
reporter => $reporter,
);
);

$rc = $muter->exec( $sub, @_ );
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/Foswiki/Contrib/core/MANIFEST
Expand Up @@ -355,6 +355,7 @@ lib/Foswiki/Address.pm 0444
lib/Foswiki/AggregateIterator.pm 0444
lib/Foswiki/Attach.pm 0444
lib/Foswiki/Attrs.pm 0444
lib/Foswiki/Aux/MuteOut.pm 0444
lib/Foswiki/Compatibility.pm 0444
lib/Foswiki/Configure/Auth.pm 0444
lib/Foswiki/Configure/Bootstrap.pm 0444
Expand Down

0 comments on commit 27821cd

Please sign in to comment.