我现在的解决方法是避免在这种情况下使用is参数,而是根据需要声明读者和编写者.
use strict;use warnings;my %moose_args = ( isa => 'ArrayRef[Str]',is => 'ro',default => sub {[]},);my %moose_attr_helper_args = ( Metaclass => 'Collection::Array',provIDes => { elements => 'get_all_cards',},);package DeckA;use Moose;use MooseX::FollowPBP;use MooseX::AttributeHelpers;has 'cards' => (%moose_args);package DeckB;use Moose;use MooseX::FollowPBP;use MooseX::AttributeHelpers;has 'cards' => (%moose_args,%moose_attr_helper_args);package main;for my $class (qw(DeckA DeckB)){ my $deck = $class->new; print "\n$class\n"; for my $method ( qw(cards get_cards get_all_cards) ){ print "$method: ",$deck->can($method) ? 'yes' : 'no',"\n"; }}
输出:
DeckAcards: noget_cards: yesget_all_cards: noDeckBcards: yes # Not what I expected.get_cards: no # Not what I expected.get_all_cards: yes解决方法 当您使用MX :: AH的元类选项时,它们不起作用.
然而,最新的Moose已经集成了对原生助手的支持,并略微调整了API.此版本使用traits(应用于属性的角色),它应该可以正常使用MX :: FollowPBP.
总结以上是内存溢出为你收集整理的perl – MooseX :: AttributeHelpers和MooseX :: FollowPBP是否正确交互?全部内容,希望文章能够帮你解决perl – MooseX :: AttributeHelpers和MooseX :: FollowPBP是否正确交互?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)