Accessor generation is very handy when you've got a 'big' object model sketched out - the nouns of your application - and you'd like to flesh out that model quickly in Perl, so you can get on to how those objects interact. It's also good coding practice to reduce redundant code, and accessor/mutator generation helps quite a bit there.
I've used Class::Accessor several times, and it's pretty easy-going. It's very good for cases where you have many classes to implement, and they're all fairly similar (in the since that they are all composites of each other or simple scalar datatypes). It's easy to have validating mutators. Class::Accessor is also nice about not getting in your way; if you want, you can use it to generate only some of your methods, and hand-code the "interesting" ones yourself.
Class::Accessor can also be used on-the-fly (at runtime) to add new methods, though most people won't need such a fancy trick. Just call $obj->mk_accessor() and you can add bells and whistles as needed. But most object models don't need to go around redefining their schemas.
Class::MethodMaker, Class::MakeMethods, and many other approaches want to be compile-time only, which might be "safer", or at least "saner". In other words, you define your classes in like this (varies a bit):
use Class::MyFavoriteMethodGenerator qw( YOUR-CLASS-DEF-HERE );
where YOUR-CLASS-DEF-HERE is usually a hash of attribute names and options (read-only, etc).
Class::MakeMethods is much more ambitious about generating more complex methods for you, while trying to keep your class definition code as simple as possible. Try it, and see if you like it.
In reply to Re: Modules for autogenerating accessor/mutator methods
by other90percent
in thread Modules for autogenerating accessor/mutator methods
by srdst13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |