aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2014-06-20 17:58:48 +1200
committerTom Ryder <tom@sanctum.geek.nz>2014-06-20 18:07:02 +1200
commit4fa04bab6f33c26704e2e6d4d3cbc22f3a2971e9 (patch)
treee22bd3f13f83393a81f0c7c36e53c6fff9dd3b6c /bin
parentSimplify required Perl version (diff)
downloadMail-Run-Crypt-4fa04bab6f33c26704e2e6d4d3cbc22f3a2971e9.tar.gz
Mail-Run-Crypt-4fa04bab6f33c26704e2e6d4d3cbc22f3a2971e9.zip
Use IPC::Run3 rather than IPC::Open3
IPC::Open3 is recommended by Perl::Critic, but it's a relatively low-level tool that requires system select() calls and careful attention to buffering/blocking, among other things. It looks like it's great if you need fine-tuned detail like that, but in this case, I don't, I just need something better than system() that will capture both stdout and stderr from a call. IPC::Run3 is by the same author and much better suited to this purpose.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/croncrypt23
1 files changed, 3 insertions, 20 deletions
diff --git a/bin/croncrypt b/bin/croncrypt
index 3d903e0..a47069b 100755
--- a/bin/croncrypt
+++ b/bin/croncrypt
@@ -38,10 +38,9 @@ our $VERSION = 0.1;
# Pull in some required modules
use Carp;
-use IPC::Open3;
+use IPC::Run3;
use Mail::GnuPG;
use MIME::Entity;
-use Symbol 'gensym';
# Bail if run without arguments
if ( !@ARGV ) {
@@ -73,25 +72,9 @@ my $recipient = $ENV{MAILTO};
my $key = $ENV{CRONCRYPT_KEYID};
my $passphrase = $ENV{CRONCRYPT_PASSPHRASE};
-# Establish filehandles; need to specifically create symbol for stderr
-my ( $stdin, $stdout, $stderr );
-$stderr = gensym;
-
# Run the command in the arguments and wait for it to finish
-my $pid = open3( $stdin, $stdout, $stderr, @ARGV );
-waitpid $pid, 0;
-
-# Read any and all output and errors
-my @output = <$stdout>;
-my @errors = <$stderr>;
-
-# Close the filehandles, placating Perl::Critic with return checks
-close $stdin
- or croak('Could not close stdin');
-close $stdout
- or croak('Could not close stdout');
-close $stderr
- or croak('Could not close stderr');
+my ( @output, @errors );
+run3( \@ARGV, undef, \@output, \@errors );
# If there was output, mail it
if (@output) {