Getopt-Mixed
view release on metacpan or search on metacpan
lib/Getopt/Mixed.pm view on Meta::CPAN
return &$badOption($i,$option,$problem) unless $opt;
$optType = $options{$opt};
if ($optType =~ /^[^:=]/) {
$opt = $optType;
$optType = $options{$opt};
}
$value = &$checkArg($i,$value,$prettyOpt,$optType);
} # end if long option
else {
# It's a short option:
$opt = substr($option,1,1);
$opt =~ tr/A-Z/a-z/ if $ignoreCase;
return &$badOption($i,$option) unless defined $options{$opt};
$optType = $options{$opt};
if ($optType =~ /^[^:=]/) {
$opt = $optType;
$optType = $options{$opt};
}
if (length($option) == 2 or $optType) {
# This is the last option in the group, so remove the group:
splice(@ARGV,$i,1);
} else {
# Just remove this option from the group:
substr($ARGV[$i],1,1) = "";
}
if ($optType) {
$value = (length($option) > 2) ? substr($option,2) : undef;
$value =~ s/^=// if $value; # Allow either -d3 or -d=3
} # end if option takes an argument
$prettyOpt = substr($option,0,2);
$value = &$checkArg($i,$value,$prettyOpt,$optType);
} # end else short option
($opt,$value,$prettyOpt);
} # end nextOption
#---------------------------------------------------------------------
# Get options:
#
# Input:
# The same as for init()
# If no parameters are supplied, init() is NOT called. This allows
# you to call init() yourself and then change the configuration
# variables.
#
# Output Variables:
# Sets $opt_X for each `-X' option encountered.
#
# Note that if --apple is a synonym for -a, then --apple will cause
# $opt_a to be set, not $opt_apple.
sub getOptions
{
&init if $#_ >= 0; # Pass arguments (if any) on to init
# If you want to use $RETURN_IN_ORDER, you have to call
# nextOption yourself; getOptions doesn't support it:
$order = $PERMUTE if $order == $RETURN_IN_ORDER;
my ($option,$value,$package);
$package = (caller)[0];
while (($option, $value) = nextOption()) {
$option =~ s/\W/_/g; # Make a legal Perl identifier
$value = 1 unless defined $value;
my $code = "\$" . $package . "::opt_$option = \$value;";
$code =~ /(.+)/; # Untaint it
eval $1;
} # end while
cleanup();
} # end getOptions
#=====================================================================
# Package return value:
$VERSION;
__END__
=head1 NAME
Getopt::Mixed - [OBSOLETE] getopt processing with both long and short options
=head1 VERSION
This document describes version 1.12 of
Getopt::Mixed, released February 8, 2014.
=head1 SYNOPSIS
use Getopt::Mixed;
Getopt::Mixed::getOptions(...option-descriptions...);
...examine $opt_* variables...
or
use Getopt::Mixed "nextOption";
Getopt::Mixed::init(...option-descriptions...);
while (($option, $value) = nextOption()) {
...process option...
}
Getopt::Mixed::cleanup();
=head1 DESCRIPTION
B<This module is obsolete.>
This package was my response to the standard modules Getopt::Std and
Getopt::Long. Std doesn't support long options, and Long
didn't support short options. I wanted both, since long options are
easier to remember and short options are faster to type.
However, years ago Getopt::Long was changed to support short
options as well, and it has the huge advantage of being part of the
standard Perl distribution. So, Getopt::Mixed is now effectively
obsolete. I don't intend to make any more changes, but I'm leaving it
available for people who have code that already uses it. For new
modules, I recommend using Getopt::Long like this:
use Getopt::Long 2.17; # Released with Perl 5.005
( run in 0.947 second using v1.01-cache-2.11-cpan-6de40a662fe )