package Pod
::Perldoc
::GetOptsOO
;
# Rather like Getopt::Std's getopts
# Call Pod::Perldoc::GetOptsOO::getopts($object, \@ARGV, $truth)
# Given -n, if there's a opt_n_with, it'll call $object->opt_n_with( ARGUMENT )
# (e.g., "-n foo" => $object->opt_n_with('foo'). Ditto "-nfoo")
# Otherwise (given -n) if there's an opt_n, we'll call it $object->opt_n($truth)
# Otherwise we try calling $object->handle_unknown_option('n')
# (and we increment the error count by the return value of it)
# If there's no handle_unknown_option, then we just warn, and then increment
# The return value of Pod::Perldoc::GetOptsOO::getopts is true if no errors,
## sburke@cpan.org 2002-10-31
BEGIN { # Make a DEBUG constant ASAP
*DEBUG
= defined( &Pod
::Perldoc
::DEBUG
)
my($target, $args, $truth) = @_;
"Starting switch processing. Scanning arguments [@$args]\n"
) if $target->can('aside');
$truth = 1 unless @_ > 2;
DEBUG
> 3 and print " Truth is $truth\n";
while( @
$args and ($_ = $args->[0]) =~ m/^-(.)(.*)/s ) {
my($first,$rest) = ($1,$2);
if ($_ eq '--') { # early exit if "--"
my $method = "opt_${first}_with";
if( $target->can($method) ) { # it's argumental
if($rest eq '') { # like -f bar
warn "Option $first needs a following argument!\n" unless @
$args;
} else { # like -fbar (== -f bar)
DEBUG
> 3 and print " $method => $rest\n";
$target->$method( $rest );
# Otherwise, it's not argumental...
if( $target->can( $method = "opt_$first" ) ) {
DEBUG
> 3 and print " $method is true ($truth)\n";
$target->$method( $truth );
# Otherwise it's an unknown option...
} elsif( $target->can('handle_unknown_option') ) {
and print " calling handle_unknown_option('$first')\n";
$target->handle_unknown_option( $first ) || 0
warn "Unknown option: $first\n";
if($rest eq '') { # like -f
} else { # like -fbar (== -f -bar )
DEBUG
> 2 and print " Setting args->[0] to \"-$rest\"\n";
"Ending switch processing. Args are [@$args] with $error_count errors.\n"
) if $target->can('aside');