Getopt modules 11: Getopt::Lucid

About this mini-article series. Each day for 24 days, I will be reviewing a module that parses command-line options (such module is usually under the Getopt::* namespace). First article is here.

Getopt::Lucid is David Golden's (DAGOLDEN) take on option parsing. It was first released in 2005 and still sees updates from time to time. The last release is in Aug 2016. Around 20 CPAN distributions use it (some of them are David's), making it moderately popular (behind Getopt::Long::Descriptive or things like MooseX::Getopt and MooX::Options).


Getopt::Lucid implements its own parsing and does not depend on Getopt::Long. It presents a more OO interface and avoids using symbols like Getopt::Long's :s
or =s@. Compared to Smart::Options which also uses method chaining style, I find Getopt::Lucid clearer because the method chains are done on a per-option basis instead of for the whole options set.

Compared to Getopt::Long, Getopt::Lucid supports: specifying an option's default value, specifying that an option is required, and specifying extra validation rule for each option. It does not allow specifying per-option summary string for nicer generation of usage message, although with its interface, adding such feature should be easily done. It does not offer automatic –help or –version message. It does not support auto-abbreviation.

Getopt::Lucid also allows you to express dependencies between options, a feature not usually found in other option parsing modules. Although currently the dependency relationship supported is just one form: Param('foo')->needs('bar')
means that when –foo is specified then –bar also needs to appear. There is no support to express mutual exclusiveness, for example.

Getopt::Lucid comes with its own peculiarities. For example, a long option can be specified as –foo but can also as foo. I haven't found a Unix program that behaves like this. I also notice that it does not allow an option named -?. And, case-sensitivity of option is regulated on a per-option basis.

There is no built-in support for config files, but the documentation shows how to do it. Basically, Getopt::Lucid wants to allow the user to customize how values from config files should be merged with values from the command-line options.

Conclusion: The ability to express dependency between options is useful, especially if the other dependency relationships (like mutual exclusiveness) were supported. Otherwise, I'd probably still reach for modules that allow automatic generation of usage/help/version message.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s