这是MooseX :: Getopt的正确(预期)用法吗?

时间:2019-03-12 04:05:32

标签: perl moose getopt-long

这是对MooseX::Getopt的正确使用吗?该文档没有很多示例。该代码有效,但是我不知道这是否是预期的使用模型。

package AppOpt {
    use Moose;
    use Moose::Util::TypeConstraints;
    use namespace::autoclean;

    with 'MooseX::Getopt';

    enum 'ReportType', [qw( activityByEvent activityByDate final )];
    enum 'FormatType', [qw( text pretty html )];

    has report => ( is => 'ro', isa => 'Str', required => 1 );

    has verbose => ( is => 'ro', isa => 'Bool', default => 0 );

    has format => ( is => 'ro', isa => 'Str', default => "text" );

    __PACKAGE__->meta->make_immutable;
}

package main;
use strict;
use warnings;

my $opt = AppOpt->new_with_options();

printf("original \@ARGV = [%s]\n\n", join(' ', @ARGV));

# Please ignore this tasteless inspection of the object guts. -E
for my $k (keys(%{$opt})) {
    unless($k =~ /(usage|ARGV|extra_argv)/) {
    printf("%s => %s\n", $k, $$opt{$k});
    }
}
exit(0);

具体来说:这些选项是否打算成为自己的类?我不确定文档中的内容。

此外,使用BUILD来进一步验证选项是否合适?

这听起来可能不止一个问题,但我并不是故意要这样。在尝试其他模块之前,我发现我误解了它们的预期用途。

0 个答案:

没有答案