MooSex :: Getopt는 어디에나 처리되지 않은 토큰을 넣습니다
-
21-12-2019 - |
문제
나는이 단편을 가지고있다
package AppOpt;
use Moose;
use namespace::autoclean;
with 'MooseX::Getopt';
has opt1 => (is => 'ro', isa => 'Str', required => 1);
has opt2 => (is => 'ro', isa => 'Bool', required => 1);
__PACKAGE__->meta->make_immutable;
1;
package main;
use strict;
use Data::Dumper;
my $cl = [qw( --opt1 OP1 --opt2 -- xxx yyy zzz)];
my $left = [];
my $opt = AppOpt->new_with_options( argv=>$cl, extra_argv => $left);
print Dumper(opt1 => $opt->opt1, opt2 => $opt->opt2, left => $left, cl => $cl);
.
이 나에게 이것을주는
$VAR1 = 'opt1';
$VAR2 = 'OP1';
$VAR3 = 'opt2';
$VAR4 = 1;
$VAR5 = 'left';
$VAR6 = [];
$VAR7 = 'cl';
$VAR8 = [
'--opt1',
'OP1',
'--opt2',
'--',
'xxx',
'yyy',
'zzz'
];
.
배열을 재 처리 할 필요없이 XXX, YYY, ZZZ와 같은 처리되지 않은 비 옵션 기반 항목을 어떻게 유지할 수 있습니까?
해결책
arrayref를 extra_argv
에 할당 할 필요가 없습니다.추가 args는 자동으로 ArrayRef에 할당됩니다.
use Data::Dumper;
my $opt = AppOpt->new_with_options(
argv => [qw( --opt1 OP1 --opt2 -- xxx yyy zzz)]
);
print Dumper $opt->extra_argv;
. 제휴하지 않습니다 StackOverflow