如何将数组从 weaver.ini 传递到 Pod::Weaver 插件

发布于 2024-11-28 09:29:00 字数 822 浏览 2 评论 0原文

因此,为了在 weaver.ini 中传递某些内容,插件本身需要一个 Moose 属性。因此,如果我在 weaver.ini 中有类似的内容,

[Acknowledgements]
contributors = 'test foo' 'foo bar'

我的插件中需要一个相应的属性。

has contributors => (
    is      => 'rw',
    isa     => 'ArrayRef[Str]',
    traits  => [ 'Array' ],
    default => sub { [ ] },
    handles => {
        contributors_count => 'count',
    },
);

但是,我收到错误

Attribute (contributors) does not pass the type constraint because: Validation failed for 'ArrayRef[Str]' with value 'test foo' 'foo bar' at /home/xenoterracide/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/x86_64-linux-thread-multi/Moose/Meta/Attribute.pm line 1248

,我不确定我哪里出错了。我尝试更改 weaver.ini 中的语法,但似乎并非如此。

So it appears that in order to pass something in weaver.ini the plugin itself requires a Moose attribute. So if I have something like this in weaver.ini

[Acknowledgements]
contributors = 'test foo' 'foo bar'

I need a corresponding attribute in my plugin.

has contributors => (
    is      => 'rw',
    isa     => 'ArrayRef[Str]',
    traits  => [ 'Array' ],
    default => sub { [ ] },
    handles => {
        contributors_count => 'count',
    },
);

However, I'm getting the error

Attribute (contributors) does not pass the type constraint because: Validation failed for 'ArrayRef[Str]' with value 'test foo' 'foo bar' at /home/xenoterracide/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/x86_64-linux-thread-multi/Moose/Meta/Attribute.pm line 1248

I'm not sure where I'm going wrong. I've tried changing the syntax up in weaver.ini but that doesn't seem to be it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫嚣ゝ 2024-12-05 09:29:00

.ini 语法略有不同。

[Acknowledgements]
contributor = test foo
contributor = foo bar

除此之外,您还必须告诉 Config::MVP(它负责 Dist::Zilla 的配置加载)您的插件的 contributor 选项可能有多个值:

sub mvp_multivalue_args { qw(contributors) }

The .ini syntax for that is slightly different.

[Acknowledgements]
contributor = test foo
contributor = foo bar

In addition to that, you'll have to tell Config::MVP, which is what takes care of Dist::Zilla's config loading, that your plugin's contributor option may have multiple values:

sub mvp_multivalue_args { qw(contributors) }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文