NAME

Getopt::Lazier - Lazy Getopt-like command-line options and argument parser

VERSION

Version 0.06

SYNOPSIS

my ($opt, @DARG) = Getopt::Lazier->new(@ARGV);

EXAMPLE USAGE

Lazy:

use Getopt::Lazier;

my ($opt, @DARG) = Getopt::Lazier->new(@ARGV);

use Data::Dumper; print Dumper([$opt, \@DARG])."\n";

# perl lazyscript.pl -help a b c d --meow=5345923 -awoo="doggo vibes" -- --this-aint-no-option

$VAR1 = [
   {
      'awoo' => 'doggo vibes',
      'meow' => '5345923',
      'help' => 1
   },
   [
      'a',
      'b',
      'c',
      'd',
      '--this-aint-no-option'
   ]
];

Lazier:

use Getopt::Lazier;

my $opt = Getopt::Lazier->new();

use Data::Dumper; print Dumper([$opt, \@ARGV])."\n";

# perl lazierscript.pl -o -p ok

$VAR1 = [
   {
      'o' => 1,
      'p' => 1
   },
   [
      'ok'
   ]
];

More Lazier:

use Getopt::Lazier "ovar";

use Data::Dumper; print Dumper([{%ovar}, $ovar, \@ARGV])."\n";

# perl t.pl --opt1=val arg --opt2 arg2

$VAR1 = [
   {
      'opt1' => 'val',
      'opt2' => 1
   },
   {
      'opt1' => 'val',
      'opt2' => 1
   },
   [
      'arg',
      'arg2'
   ]
];

SUBROUTINES/METHODS

new

The laziest way to parse arguments tho. Returns a hashref of parsed options, and (if called in list context) an array of remaining arguments. new takes a list/array as an argument, and if unspecified will use @ARGV by default.

import

Now with namespace fuckery! Passing a string to the use pragma will make the import method run new automatically on @ARGV and import the string as variable names in package main.

For example:

use Getopt::Lazier "options";

Will import both %options (a hash of the parsed options), and (for backwards compatability) $options (a reference to the hash). If the script was passed --help on the command line, both $options{help} and $options->{help} would be set to 1.

AUTHOR

Jojess Fournier, <jojessf@cpan.org>, Dave Maez

BUGS

Please report any bugs or feature requests to bug-getopt-lazier at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Getopt-Lazier. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Getopt::Lazier

You can also look for information at:

https://github.com/jojessf/GetOptLazier

ACKNOWLEDGEMENTS

Thanks to Dave for the ENV addition. Also for being awesome. :3

LICENSE AND COPYRIGHT

This software is Copyright (c) 2024 by Jojess Fournier.

This is free software, licensed under:

GNU GENERAL PUBLIC LICENSE 3.0