aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--README.markdown7
-rwxr-xr-xbin/croncrypt23
-rw-r--r--share/man/man1/croncrypt.12
3 files changed, 7 insertions, 25 deletions
diff --git a/README.markdown b/README.markdown
index 217d0c6..5ca520b 100644
--- a/README.markdown
+++ b/README.markdown
@@ -26,15 +26,14 @@ Put the `croncrypt` binary somewhere in your `crontab`’s `PATH`, and install
the following Perl modules:
* `Carp`
-* `IPC::Open3`
+* `IPC::Run3`
* `Mail::GnuPG`
* `MIME::Entity`
-* `Symbol`
On Debian-derived systems, this should do the trick:
- # aptitude install perl-base perl-modules \
- libmail-gnupg-perl libmime-tools-perl
+ # aptitude install perl-base perl-modules libmail-gnupg-perl \
+ libmime-tools-perl libipc-run3-perl
License
-------
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) {
diff --git a/share/man/man1/croncrypt.1 b/share/man/man1/croncrypt.1
index 41ea87a..dd5b508 100644
--- a/share/man/man1/croncrypt.1
+++ b/share/man/man1/croncrypt.1
@@ -21,7 +21,7 @@ Don't use your own GPG key for signing! I recommend you create a dedicated key
just for Croncrypt, and sign it locally with gpg --lsign so that your software
trusts it locally.
.SH SEE ALSO
-gpg(1), gpg-agent(1), Mail::GnuPG(3pm), MIME::Entity(3pm)
+gpg(1), gpg-agent(1), IPC::Run3(3pm), Mail::GnuPG(3pm), MIME::Entity(3pm)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>