In perl,is there a module that automatically generates set/get accessor methods?
Anyone knows such a module?开发者_运维问答
Write it myself is just tedious..
Moose will actually do this for you although it may not be in the most intuitive way.
Class::Accessor
is pretty standard, for non-Moose Perl.
MooseX::Declare might be what you are looking for.
You could use Moose
as others have pointed out. For a lighter implementation, you could use Class::Accessor
. Furthermore, it has an optional Moose-like interface as well.
Class::Accessor
has a follow_best_practice
method which will enforce setters and getters to follow Damian Conway's advice in Perl Best Practices about their naming.
Mouse (Esp Mouse::XS) seems to get the best performance these days (YMMV). It's like a lightweight moose.
Class::XSAccessor will generate very fast accessors and has some flexibility, but I would recommend skipping directly to Mouse which is a faster, slimmer, compatible Moose which is a complete OO system.
Use Moose to automatically generate set/get accessor methods
https://metacpan.org/pod/Moose
精彩评论