Getopt-Module
view release on metacpan or search on metacpan
#!/usr/bin/env perl
use strict;
use warnings;
use Carp qw(confess);
use Test::More;
# arbitrary Getopt::Long option name
# (parsing depends on the params passed to GetModule, not the option name)
use constant OPTION_NAME => 'module';
sub pp($) { Getopt::Module::_pp($_[0]) }
sub _qw_to_split($) {
my $evals = shift;
my $ref = ref($evals);
$evals = [ $evals ] unless ($ref);
my $spaces_to_commas = sub($) {
join(',', split(qr{\s+}, shift));
};
my $qw_to_split = sub($) {
my $NUL = "\0";
sprintf('split(/,/,q%s%s%s)', $NUL, $spaces_to_commas->($_[0]), $NUL);
};
my $rv = [
map {
my $eval = $_;
$eval =~ s{\bqw\(([^)]+)\)}{$qw_to_split->("$1")}eg;
$eval;
} @$evals
];
return $ref ? $rv : $rv->[0];
}
sub is_parsed {
my $target = shift;
my $_want = pop;
my $value = pop;
my $options = {};
my $tb = Test::More->builder;
# report errors with caller's line number
local $Test::Builder::Level = $Test::Builder::Level + 1;
confess 'target must be a ref' unless (ref $target);
if (@_) {
$options = @_ == 1 ? shift : { @_ };
}
confess 'options must be a hashref' unless (ref($options) eq 'HASH');
my $ref = ref($_want);
my $want;
# $want can be the expected target, or a subset of the parsed components
# (hash) returned by GetModule. if it's the former, convert it into the
# latter.
#
# XXX squashed bug: watch out for perl flakiness if trying to do (something
# like) this without an intermediary temp value:
#
# $want = { target => \$want }
if (($ref eq 'HASH') && ($_want->{eval})) {
$_want->{eval} = _qw_to_split($_want->{eval});
$want = $_want;
( run in 1.197 second using v1.01-cache-2.11-cpan-5b529ec07f3 )