14.7. Interapplication Consistency
Tools such as Getopt::Long, Getopt::Clade, and Getopt::Euclid make it easy to follow the advice of the "Command-Line Structure" guideline to enforce a single consistent command-line structure across all of your applications. If you're using Getopt::Long or Getopt::Clade, you can simply create a module that provides a suitable description of the standard interface. For example, if you're using Getopt::Clade, you might create a module (such as in Example 14-6) that provides the standard interface features that every application is expected to provide: Example 14-6. Standard interface components for Getopt::Clade
package Corporate::Std::Cmdline;
use strict;
use warnings;
use Getopt::Clade q{
-i[n] [=] <file:in> Specify input file [default: '-']
-o[ut] [=] <file:out> Specify output file [default: '-']
-v Print all warnings
--verbose [ditto]
};
1; You could then reuse it in each program you created. For example, you could refactor Example 14-4 to Example 14-7. Example 14-7. Standardized command-line parsing via Getopt::Clade
Getopt::Euclid allows you to construct interface specification modules in a similar way. The main difference is that those modules mainly contain POD (see Example 14-8). Example 14-8. Standard interface components for Getopt::Euclid
package Corporate::Std::Cmdline;
use Getopt::Euclid;
1; Once that module was installed in the normal way, you could refactor Example 14-5 to the implementation shown in Example 14-9. Note that, once again, only the application-specific arguments need to be specified within the application itself. Example 14-9. Standardized command-line parsing via Getopt::Euclid
![]() |