summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org> 2015-01-03 18:32:29 +0100
committerGravatar Steven Schubiger <stsc@refcnt.org> 2015-01-03 18:32:29 +0100
commit259a08fb7474636756c48f96bcfe60c015e86d63 (patch)
tree04df5d59053cb307ae7d75d4739bd45ac1b0b211
parent2eeaf2830b8ec5df9a50488d58993275f9ef1387 (diff)
downloaddistdns-259a08fb7474636756c48f96bcfe60c015e86d63.tar.gz
distdns-259a08fb7474636756c48f96bcfe60c015e86d63.tar.bz2
Trap module inclusion/import failures
-rwxr-xr-xclient.pl50
1 files changed, 36 insertions, 14 deletions
diff --git a/client.pl b/client.pl
index cbf9b58..3335981 100755
--- a/client.pl
+++ b/client.pl
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
-# Copyright (c) 2013 Michel Ketterle, Steven Schubiger
+# Copyright (c) 2015 Michel Ketterle, Steven Schubiger
#
# This file is part of distdns.
#
@@ -21,19 +21,41 @@ use strict;
use warnings;
use constant false => 0;
-use Config::Tiny;
-use Digest::MD5 qw(md5_hex);
-use Fcntl ':flock';
-use File::Spec::Functions qw(catfile rel2abs);
-use FindBin qw($Bin);
-use Getopt::Long qw(:config no_auto_abbrev no_ignore_case);
-use JSON qw(decode_json);
-use LWP::UserAgent;
-use POSIX qw(strftime);
-use Sys::Hostname qw(hostname);
-use Tie::File;
-
-my $VERSION = '0.06';
+BEGIN
+{
+ my @modules = (
+ [ 'Config::Tiny', [ ] ],
+ [ 'Digest::MD5', [ qw(md5_hex) ] ],
+ [ 'Fcntl', [ qw(:flock) ] ],
+ [ 'File::Spec::Functions', [ qw(catfile rel2abs) ] ],
+ [ 'FindBin', [ qw($Bin) ] ],
+ [ 'Getopt::Long', [ qw(:config no_auto_abbrev no_ignore_case) ] ],
+ [ 'JSON', [ qw(decode_json) ] ],
+ [ 'LWP::UserAgent', [ ] ],
+ [ 'POSIX', [ qw(strftime) ] ],
+ [ 'Sys::Hostname', [ qw(hostname) ] ],
+ [ 'Tie::File', [ ] ],
+ );
+ my (@missing, @import);
+ foreach my $module (@modules) {
+ unless (eval "require $module->[0]; 1") {
+ push @missing, $module->[0];
+ next;
+ }
+ unless (eval { $module->[0]->import(@{$module->[1]}); 1 }) {
+ push @import, $module->[0];
+ }
+ }
+ if (@missing || @import) {
+ warn <<"EOT";
+Modules missing: @missing
+Import failures: @import
+EOT
+ exit 1;
+ }
+}
+
+my $VERSION = '0.07';
my $conf_file = catfile($Bin, 'client.conf');