| 1 |
NAMES |
| 2 |
Class::Accessor - automated accessor generation |
| 3 |
Class::Accessor::Fast - faster automated accessor generation |
| 4 |
Class::Accessor::Faster - even faster, using an array |
| 5 |
|
| 6 |
DESCRIPTION |
| 7 |
|
| 8 |
This module automagically generates accessors/mutators for your class. |
| 9 |
|
| 10 |
Most of the time, writing accessors is an exercise in cutting and |
| 11 |
pasting. You usually wind up with a series of almost identical methods, |
| 12 |
one for each piece of data in your object. While some will be unique, |
| 13 |
doing value checks and special storage tricks, most will simply be |
| 14 |
exercises in repetition. |
| 15 |
|
| 16 |
If you make your module a subclass of Class::Accessor and declare your |
| 17 |
accessor fields with mk_accessors() then you'll find yourself with a set |
| 18 |
of automatically generated accessors, which can even be customized! |
| 19 |
|
| 20 |
The basic set up is very simple: |
| 21 |
|
| 22 |
package My::Class; |
| 23 |
use base qw(Class::Accessor); |
| 24 |
My::Class->mk_accessors( qw(foo bar car) ); |
| 25 |
|
| 26 |
Done. My::Class now has simple foo(), bar() and car() accessors defined. |
| 27 |
|
| 28 |
If you prefer a Moose-like interface you can do this instead: |
| 29 |
|
| 30 |
package My::Class; |
| 31 |
use Class::Accessor "moose-like"; |
| 32 |
has foo => ( is => "rw" ); |
| 33 |
has bar => ( is => "rw" ); |
| 34 |
has car => ( is => "rw" ); |
| 35 |
|
| 36 |
Done, again. |
| 37 |
|
| 38 |
AUTHOR |
| 39 |
|
| 40 |
Copyright 2017 Marty Pauley <[email protected]> |
| 41 |
|
| 42 |
This program is free software; you can redistribute it and/or modify it |
| 43 |
under the same terms as Perl itself. That means either (a) the GNU |
| 44 |
General Public License or (b) the Artistic License. |
| 45 |
|