Permalink
Browse files

Item14205: Change to the new Aux::MuteOut module

Thanks to VadimBelman for the new capture module
  • Loading branch information...
gac410 committed Nov 14, 2016
1 parent d857659 commit 27821cd0f1c67e04a32ded9ac4c1bbf9d441008b
Showing with 6 additions and 76 deletions.
  1. +5 −76 core/lib/Foswiki/Configure/Wizards/AutoConfigureEmail.pm
  2. +1 −0 core/lib/Foswiki/Contrib/core/MANIFEST
@@ -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;
@@ -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;
@@ -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, @_ );
}
@@ -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

0 comments on commit 27821cd

Please sign in to comment.