The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

VERSION

This document describes version 0.08 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:

  • 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      run_gl     load_gl run_gl_less load_gl_less load_gl_evenless run_gl_evenless   perl
 run_gl            66.4+-0.64/s          --       -5.9%      -71.3%       -71.5%           -80.9%          -81.3% -89.6%
 load_gl          70.59+-0.16/s     6.3+-1%          --      -69.4%       -69.7%           -79.7%          -80.1% -89.0%
 run_gl_less         231+-1.1/s 247.9+-3.7% 227.3+-1.7%          --        -0.8%           -33.4%          -34.8% -64.0%
 load_gl_less      232.8+-1.9/s 250.6+-4.4% 229.8+-2.7% 0.78+-0.94%           --           -32.9%          -34.3% -63.7%
 load_gl_evenless    347+-9.7/s    423+-15%    392+-14%  50.2+-4.3%   49.1+-4.3%               --           -2.1% -45.9%
 run_gl_evenless     354.5+-4/s 433.9+-7.9% 402.2+-5.7%  53.4+-1.9%   52.3+-2.1%        2.2+-3.1%              -- -44.7%
 perl                641+-3.7/s    865+-11% 808.1+-5.6% 177.5+-2.1%  175.3+-2.7%       84.7+-5.3%      80.8+-2.3%     --
 
 Average times:
   perl            :     1.5601ms
   run_gl_evenless :     2.8209ms
   load_gl_evenless:     2.8818ms
   load_gl_less    :     4.2955ms
   run_gl_less     :     4.3290ms
   load_gl         :    14.1663ms
   run_gl          :    15.0602ms

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.