Remove obsolete dependency
authorHubert depesz Lubaczewski <[email protected]>
Sun, 24 Jun 2012 13:28:01 +0000 (15:28 +0200)
committerHubert depesz Lubaczewski <[email protected]>
Sun, 24 Jun 2012 13:28:01 +0000 (15:28 +0200)
Getopt::Mixed was obsolete since at least March 2007. Use standard, core
perl module Getopt::Long instead.

In passing, add long option for debugging irc traffic, for consistency,
and reformat help output.

docbot.pl

index 91d4519c2124d7c6c24b3a7a7c70397b6eaa5388..05509d47c773fb52ef978cd10b9bc38f4155ea32 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -42,7 +42,7 @@ use warnings;
 use POE;
 use POE qw(Component::IRC Component::IRC::Plugin::Connector Component::IRC Component::IRC::Plugin::CTCP);
 use POE::Component::IRC;
-use Getopt::Mixed "nextOption";
+use Getopt::Long qw( :config no_ignore_case );
 use FileHandle;
 use Data::Dumper;
 use POSIX ":sys_wait_h";
@@ -88,33 +88,25 @@ init_statistics();
 ######################################################################
 # handle command line arguments
 ######################################################################
-my $args_init_string = "help h d debug D c=s config=s l=s logfile=s";
-Getopt::Mixed::init($args_init_string);
+# defaults
 $main::help = 0;
 $main::debug = 0;
 $main::debug_traffic = 0;
 $main::config_file = "";
 # parse options
-my ($argv_option, $argv_value, $argv_pretty);
-while (($argv_option, $argv_value, $argv_pretty) = nextOption()) {
-    if ($argv_option eq "h" or $argv_option eq "help") {
-        $main::help = 1;
-    }
-    if ($argv_option eq "d" or $argv_option eq "debug") {
-        $main::debug = 1;
-    }
-    if ($argv_option eq "D") {
-        $main::debug_traffic = 1;
-    }
-    if ($argv_option eq "c" or $argv_option eq "config") {
-        $main::config_file = $argv_value;
-    }
-    if ($argv_option eq "l" or $argv_option eq "logfile") {
-        $main::logfile = $argv_value;
-    }
+my $args_init_string = "help h d debug D c=s config=s l=s logfile=s";
+unless (
+    GetOptions(
+        'help|h|?'     =>  \$main::help,
+        'debug|d'      =>  \$main::debug,
+        'debug-irc|D'  =>  \$main::debug_traffic,
+        'config|c=s'   =>  \$main::config_file,
+        'logfile|l=s'  =>  \$main::logfile,
+    )
+) {
+    # There were some errors with parsing command line options - show help.
+    $main::help = 1;
 }
-Getopt::Mixed::cleanup();
-
 
 my $shutdown = 0;
 
@@ -132,16 +124,18 @@ my $shutdown = 0;
 
 
 if ($main::help == 1) {
-    print "\n";
-    print "  $0 [options]\n";
-    print "\n";
-    print "The following options are available:\n";
-    print "  -h --help\t\tThis help\n";
-    print "  -d --debug\t\tEnable debug messages\n";
-    print "  -D\t\t\tEnable IRC traffic debugging\n";
-    print "  -c --config\t\tConfig file (required)\n";
-    print "  -l --logfile\t\tLogfile\n";
-    print "\n";
+    print <<_END_OF_HELP_;
+
+  $0 [options]
+
+The following options are available:
+  -h --help       This help
+  -d --debug      Enable debug messages
+  -D --debug-irc  Enable IRC traffic debugging
+  -c --config     Config file (required)
+  -l --logfile    Logfile
+
+_END_OF_HELP_
     exit(0);
 }