NAME

Getopt::Long::EvenLess - Like Getopt::Long::Less, but with even less features

VERSION

This document describes version 0.10 of Getopt::Long::EvenLess (from Perl distribution Getopt-Long-EvenLess), released on 2017-01-11.

DESCRIPTION

This module (GLEL for short) is a reimplementation of Getopt::Long (GL for short), but with much less features. It's an even more stripped down version of Getopt::Long::Less (GLL for short) and is perhaps less convenient to use for day-to-day scripting work.

The main goal is minimum amount of code and small startup overhead. This module is an experiment of how little code I can use to support the stuffs I usually do with GL.

Compared to GL and GLL, it:

  • has minimum Configure() support

    Only these configurations are known: pass_through, no_pass_through (default).

    GLEL is equivalent to GL in this mode: bundling, no_ignore_case, no_getopt_compat, gnu_compat, permute.

    No support for configuring via import options e.g.:

     use Getopt::Long qw(:config pass_through);
  • does not support increment (foo+)

  • no type checking (foo=i, foo=f, foo=s all accept any string)

  • does not support optional value (foo:s), only no value (foo) or required value (foo=s)

  • does not support desttypes (foo=s@)

  • does not support handler other than coderef (so no "foo=s" => \$scalar, "foo=s" => \@ary, only "foo=s" => sub { ... })

    Also, in coderef handler, code will get a simple hash instead of a "callback" object as its first argument.

  • does not support hashref as first argument

  • does not support bool/negation (no foo!, so you have to declare both foo and no-foo manually)

The result?

Amount of code. GLEL 0.07 is about 175 lines of code, while GL is about 1500. Sure, if you really want to be minimalistic, you can use this single line of code to get options:

 @ARGV = grep { /^--([^=]+)(=(.*))?/ ? ($opts{$1} = $2 ? $3 : 1, 0) : 1 } @ARGV;

and you're already able to extract --flag or --opt=val from @ARGV but you also lose a lot of stuffs like autoabbreviation, --opt val syntax support syntax (which is more common, but requires you specify an option spec), custom handler, etc.

Startup overhead. Here's a sample startup overhead benchmark:

                           Rate     load_gl      run_gl load_gl_less run_gl_less run_gl_evenless load_gl_evenless   perl
 load_gl          69.45+-0.11/s          --       -1.9%       -69.1%      -69.9%          -81.5%           -82.5% -89.8%
 run_gl           70.77+-0.19/s  1.9+-0.32%          --       -68.5%      -69.3%          -81.2%           -82.2% -89.7%
 load_gl_less      224.7+-2.1/s   223.6+-3%   217.5+-3%           --       -2.5%          -40.2%           -43.5% -67.1%
 run_gl_less       230.4+-1.8/s 231.8+-2.7% 225.6+-2.7%    2.5+-1.2%          --          -38.6%           -42.0% -66.3%
 run_gl_evenless   375.5+-4.6/s 440.7+-6.6% 430.6+-6.6%   67.1+-2.5%  62.9+-2.4%              --            -5.6% -45.1%
 load_gl_evenless  397.6+-2.2/s 472.5+-3.3% 461.8+-3.5%   76.9+-1.9%  72.6+-1.7%       5.9+-1.4%               -- -41.9%
 perl                684+-5.1/s 884.9+-7.6% 866.5+-7.7%  204.4+-3.6% 196.8+-3.2%      82.2+-2.6%         72+-1.6%     --
 
 Average times:
   perl            :     1.4620ms
   load_gl_evenless:     2.5151ms
   run_gl_evenless :     2.6631ms
   run_gl_less     :     4.3403ms
   load_gl_less    :     4.4504ms
   run_gl          :    14.1303ms
   load_gl         :    14.3988ms

FUNCTIONS

Configure(@configs | \%config) => hash

Set configuration. Known configurations:

  • pass_through

    Ignore errors (unknown/ambiguous option) and still make GetOptions return true.

  • no_pass_through (default)

Return old configuration data. To restore old configuration data you can pass it back to Configure(), e.g.:

 my $orig_conf = Getopt::Long::EvenLess::Configure("pass_through");
 # ...
 Getopt::Long::EvenLess::Configure($orig_conf);

GetOptions(%spec) => bool

Shortcut for:

 GetOptionsFromArray(\@ARGV, %spec)

GetOptionsFromArray(\@ary, %spec) => bool

Get (and strip) options from @ary. Return true on success or false on failure (unknown option, etc).

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Getopt-Long-EvenLess.

SOURCE

Source repository is at https://github.com/perlancar/perl-Getopt-Long-EvenLess.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Getopt-Long-EvenLess

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

Getopt::Long

Getopt::Long::Less

If you want more features intead of less, try Getopt::Long::More.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.