Getopt::Mini
version 0.02
use Getopt::Mini; say $ARGV{'flag'};
This is, yup, yet another Getopt module, a very lightweight one. It's not declarative in any way, ie, it does not support specs, like Getopt::Long et al do.
On the other hand, it can validate your parameters using the Data::Validator syntax. But that's a hidden feature for now (you'll need to install Data::Validator yourself and find a way to run it by reading this source code).
Getopt::Mini - yet another yet-another Getopt module
The rules:
* -<char> does not consume barewords (ie. -f, -h, ...) unless you set hungry_flags=>1 * -<str> <bareword> * --<str> <bareword> will eat up the next bare word (-type f, --file f.txt) * -<char|str>=<val> and --<str>=<val> consumes its value and nothing more * <str> gets pushed into an array in $ARGV{''}
Some code examples:
perl myprog.pl -h -file foo --file bar use Getopt::Mini; # parses the @ARGV into %ARGV say YAML::Dump \%ARGV; --- h: 1 file: - foo - bar # single flags like -h are checked with exists: say 'help...' if exists $ARGV{'h'}; # barewords are pushed into the key '_' perl myprog.pl file1.c file2.c say "file: $_" for @{ $ARGV{''} };
Or you can just use a modular version:
use Getopt::Mini later=>1; # nothing happens getopt; # imports into %ARGV my %argv = getopt; # imports into %argv instead
There's also a special mode that can be set with array = 1> that will make a flag consume all following barewords:
array =
perl myprog.pl -a -b --files f1.txt f2.txt use Getopt::Mini array => 1; say YAML::Dump \%ARGV; --- h: ~ file: - foo - bar
This is *ALPHA* software. And despite its small footprint, this is lurking with nasty bugs and potential api changes.
Complaints should be filed to the Getopt Foundation, which has been treating severe NIH syndrome since 1980.
Getopt::Whatever - no declarative spec like this module, but the options in %ARGV and @ARGV are not where I expect them to be.
Getopt::Casual - similar to this module, but very keen on turning entries into single param options.
Rodrigo de Oliveira <rodrigolive@gmail.com>
This software is copyright (c) 2013 by Rodrigo de Oliveira.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Getopt::Mini, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Getopt::Mini
CPAN shell
perl -MCPAN -e shell install Getopt::Mini
For more information on module installation, please visit the detailed CPAN module installation guide.