Getopt-EX-Hashed
view release on metacpan or search on metacpan
t/08_must.t view on Meta::CPAN
must => sub {
grep { lc($_[1]) eq $_ } qw(life universe everything);
};
has nature => spec => '=s%', default => {},
must => sub {
grep { lc($_[2]) eq $_ } qw(paranoid);
};
VALID: {
local @ARGV = qw(--answer 42
--answer-is 42
-q life
-q universe
-q everything
--nature Marvin=Paranoid
);
my $app = Getopt::EX::Hashed->new() or die;
GetOptions($app->optspec); # or die;
is($app->{answer}, 42, "Number");
is($app->{answer_is}, "Answer is 42", "Number with action");
is_deeply($app->{question}, [ "life", "universe", "everything" ], "List");
is($app->{nature}->{Marvin}, "Paranoid", "Hash");
}
INVALID: {
local @ARGV = qw(--answer 41
--answer-is 41
-q life
-q space
-q everything
-nature Marvin=Sociable
);
# has [ qw(+answer +answer_is +question +nature) ] => must => undef;
my $app = Getopt::EX::Hashed->new() or die;
t/09_validate.t view on Meta::CPAN
has mouse => '=s',
any => [ qw(Frankie Benjy) ];
has mice => ':s',
any => [ qw(Frankie Benjy), '' ];
} no Getopt::EX::Hashed;
VALID: {
local @ARGV = qw(--answer 42
--answer-is 42
--question life
--nature Marvin=Paranoid
--nature Zaphod=Sociable
--mouse Benjy
--mice
);
my $app = Getopt::EX::Hashed->new;
$app->getopt;
t/09_validate.t view on Meta::CPAN
is($app->{answer}, 42, "Number");
is($app->{answer_is}, "Answer is 42", "Number with action");
is($app->{question}->[0], "life", "RE");
is($app->{nature}->{Marvin}, "Paranoid", "Hash");
is($app->{nature}->{Zaphod}, "Sociable", "Hash");
is($app->{mouse}, "Benjy", "List");
is($app->{mice}, "", "List (optional)");
}
INVALID: {
local @ARGV = qw(--answer 41
--answer-is 41
--question space
--mouse Benji
--nature Marvin=Sociable
--nature Zaphod=Paranoid
);
my $app = Getopt::EX::Hashed->new;
$app->getopt;
t/App/Foo.pm view on Meta::CPAN
has ARGV => default => [];
has '<>' => action => sub {
push @{$_->{ARGV}}, $_[0];
};
}
no Getopt::EX::Hashed;
sub run {
my $app = shift;
local @ARGV = @_;
use Getopt::Long;
$app->getopt or die;
return @ARGV;
}
1;
package App::Bar;
use v5.14;
t/App/Foo.pm view on Meta::CPAN
has tricia => ( spec => 'trillian=s' );
has zaphord => ( spec => '', alias => 'beeblebrox' );
has so_long => ( spec => '' );
has list => ( spec => '=s@' );
has hash => ( spec => '=s%' );
no Getopt::EX::Hashed;
sub run {
my $app = shift;
local @ARGV = @_;
use Getopt::Long;
$app->getopt or die;
return @ARGV;
}
1;
( run in 0.724 second using v1.01-cache-2.11-cpan-49f99fa48dc )