[英]Can Perl Moose create multiple accessors?
So, Perl's standard naming convention is snake_case, but I'm writing a module to interface with a REST API that uses camelCase, creating objects with the Moose infrastructure. 因此,Perl的标准命名约定是snake_case,但我正在编写一个模块来与使用camelCase的REST API进行交互,使用Moose基础结构创建对象。 I'd rather make the objects work with either case, but I can't seem to get multiple Moose-y accessors.
我宁愿让对象适用于任何一种情况,但我似乎无法获得多个Moose-y访问器。 The following is the only way I could come up with.
以下是我能想到的唯一方法。
has 'full_name' => (
is => 'rw',
isa => 'Str',
);
sub fullName {return shift->full_name(@_)};
Any better way to do this with Moose's built-ins? 用Moose的内置插件做任何更好的方法吗?
Bah, easy answer. 呸,答案很简单。 I completely overlooked
MooseX::Aliases
that allows you to do this easily: 我完全忽略了
MooseX::Aliases
,它可以让你轻松地做到这一点:
has 'full_name' => (
is => 'rw',
isa => 'Str',
alias => 'fullName', # or alias => [qw(fullName)] for even more
);
Not built-in Moose like I was thinking there would be, but definitely sufficient. 不像我想的那样内置Moose,但绝对足够。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.