R__
R__

Reputation: 1531

In perl,is there a module that automatically generates set/get accessor methods?

Anyone knows such a module?

Write it myself is just tedious..

Upvotes: 1

Views: 306

Answers (7)

Fam Khan
Fam Khan

Reputation: 51

Use Moose to automatically generate set/get accessor methods

https://metacpan.org/pod/Moose

Upvotes: 1

Schwern
Schwern

Reputation: 164689

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.

Upvotes: 1

cftarnas
cftarnas

Reputation: 1755

Mouse (Esp Mouse::XS) seems to get the best performance these days (YMMV). It's like a lightweight moose.

Upvotes: 2

Alan Haggai Alavi
Alan Haggai Alavi

Reputation: 74202

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.

Upvotes: 2

Axeman
Axeman

Reputation: 29854

Class::Accessor is pretty standard, for non-Moose Perl.

Upvotes: 5

ennuikiller
ennuikiller

Reputation: 46965

Moose will actually do this for you although it may not be in the most intuitive way.

Upvotes: 8

Quentin
Quentin

Reputation: 943211

MooseX::Declare might be what you are looking for.

Upvotes: 2

Related Questions