Pergunta

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. I'd rather make the objects work with either case, but I can't seem to get multiple Moose-y accessors. 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?

Foi útil?

Solução

Bah, easy answer. I completely overlooked MooseX::Aliases that allows you to do this easily:

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top