My company uses Getopt::Declare as its command line option parser. The structure of our option processing blocks routinely look like this:
Readonly my $ARGS => Getopt::Declare->new(
join( "\n",
"[strict]",
"--engineacct <num:i>\tEngineaccount [required]",
"--outfile <outfile:of>\tOutput file [required]",
"--clicks <N:i>\tselect keywords with more than N clicks [required]",
"--infile <infile:if>\tInput file [required]",
"--pretend\tThis option not yet implemented. "
. "If specified, the script will not execute.",
"[ mutex: --clicks --infile ]",
)
) || exit(1);
that's a lot to look at... I tried to make it a little simpler by using HEREDOCS like most of the documentation uses:
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use Readonly;
Readonly my $ARGS => Getopt::Declare->new(<<'EOPARAM');
[strict]
--client <client:i> client number [required]
--clicks <clicks:i> click threshold (must be > 5)
EOPARAM
While I think this is much easier to read, for some reason it won't recognize any of my arguments.
perl test.pl --client 5 --clicks 2
I get unrecognized arguments:
Error: unrecognizable argument ('--client')
Error: unrecognizable argument ('154')
Error: unrecognizable argument ('--clicks')
Error: unrecognizable argument ('2')
So I guess I have two quesitons:
Has anyone successfully used HEREDOCS with Getopt::Declare?
Is Getopt::Declare still a reasonable option for an option parser? As opposed to other modules like Getopt::Long