Ruey-Cheng Chen
and 1 contributors

NAME

Getopt::Lazy - Yet another lazy, minimal way of using Getopt::Long

SYNOPSIS

    use Getopt::Lazy
        'help|h' => 'Show this help screen',
        'verbose|v' => 'Show verbose output',
        'output|o=s' => ["[FILE] Send the output to FILE", 'getopt.out'],
        'output-encoding=s' => ['[ENCODING] Specify the output encoding', 'utf8'],
        -summary => 'a simple example usage of Getopt::Lazy',
        -usage => '%c %o file1 [file2 ..]',
        ;

    GetOptions;
    show_help and exit 1 unless @ARGV;

DESCRIPTION

Got tired of the same tedious "getopt" things in every script you wrote? This module works for you!

Without Getopt::Lazy

Normally your script would go like this:

    use File::Basename;
    use Getopt::Long;

    sub usage {
        my $msg = shift;
        my $cmd = basename $0;
        print $msg, "\n" if defined $msg;
        print <<__USAGE__;
    $cmd - Yet another tool for whatever you like
    Usage:  $cmd [options...] file [more-file]
    Options:
            --boolean,-b                        Turn on the function A
            --string, -s STRING                 Specify the name of blahblah (defaults 'blahblah')
            --another-string, -as STRING        Specify an alias for blahblah (defaults 'blahblah')
            ...
    __USAGE__
    }

    my $boolean = 0;
    my $string = 'blahblah';
    my $another_string = 'blahblah';
    ...

    GetOptions(
        'boolean|b' => \$boolean,
        'string|s=s' => \$string,
        'another-string|as=s' => \$string,
        ...
    );

    usage and exit unless @ARGV;

With Getopt::Lazy

The same thing using Getopt::Lazy:

    use Getopt::Lazy
        'boolean|b' => 'Turn on the function A',
        'string|s=s' => ['[STRING] Specify the name of blahblah' => 'blahblah'],
        'another-string|as=s' => ['[STRING] Specify an alias for blahblah' => 'blahblah'],
        -summary => 'Yet another tool for whatever you like',
        -usage => '%c %o file1 [more-file]',
        ;

    GetOptions;
    show_help and exit 1 unless @ARGV;

What We've Got?

show_help() simply prints out this help screen:

    $ lazy
    lazy - Yet another tool for whatever you like
    Usage:  lazy [options..] file1 [more-file]
    Options:
            --another-string, -as STRING    Specify an alias for blahblah (default: blahblah)
            --boolean                       Turn on the function A
            --string, -s STRING             Specify the name of blahblah (default: blahblah)

Detail Usage

Getopt::Lazy does two things for you: 1) spawning a variable for every given option, and 2) generating GNU-style help messages.

INTERFACE

show_help

Show the help screen

GetOptions

Make Getopt::Long work!

CONFIGURATION AND ENVIRONMENT

Getopt::Lazy requires no configuration files or environment variables.

DEPENDENCIES

Getopt::Lazy depends on Getopt::Long.

INCOMPATIBILITIES

None reported (so far so good.)

BUGS AND LIMITATIONS

Please report any bugs or feature requests to bug-getopt-lazy@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Ruey-Cheng Chen <rueycheng@gmail.com>

LICENCE AND COPYRIGHT

Copyright (c) 2007, 2015 Ruey-Cheng Chen <rueycheng@gmail.com>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.