|
Packit |
5f056f |
NAMES
|
|
Packit |
5f056f |
Class::Accessor - automated accessor generation
|
|
Packit |
5f056f |
Class::Accessor::Fast - faster automated accessor generation
|
|
Packit |
5f056f |
Class::Accessor::Faster - even faster, using an array
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
DESCRIPTION
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
This module automagically generates accessors/mutators for your class.
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
Most of the time, writing accessors is an exercise in cutting and
|
|
Packit |
5f056f |
pasting. You usually wind up with a series of almost identical methods,
|
|
Packit |
5f056f |
one for each piece of data in your object. While some will be unique,
|
|
Packit |
5f056f |
doing value checks and special storage tricks, most will simply be
|
|
Packit |
5f056f |
exercises in repetition.
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
If you make your module a subclass of Class::Accessor and declare your
|
|
Packit |
5f056f |
accessor fields with mk_accessors() then you'll find yourself with a set
|
|
Packit |
5f056f |
of automatically generated accessors, which can even be customized!
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
The basic set up is very simple:
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
package My::Class;
|
|
Packit |
5f056f |
use base qw(Class::Accessor);
|
|
Packit |
5f056f |
My::Class->mk_accessors( qw(foo bar car) );
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
Done. My::Class now has simple foo(), bar() and car() accessors defined.
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
If you prefer a Moose-like interface you can do this instead:
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
package My::Class;
|
|
Packit |
5f056f |
use Class::Accessor "moose-like";
|
|
Packit |
5f056f |
has foo => ( is => "rw" );
|
|
Packit |
5f056f |
has bar => ( is => "rw" );
|
|
Packit |
5f056f |
has car => ( is => "rw" );
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
Done, again.
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
AUTHOR
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
Copyright 2017 Marty Pauley <marty+perl@martian.org>
|
|
Packit |
5f056f |
|
|
Packit |
5f056f |
This program is free software; you can redistribute it and/or modify it
|
|
Packit |
5f056f |
under the same terms as Perl itself. That means either (a) the GNU
|
|
Packit |
5f056f |
General Public License or (b) the Artistic License.
|
|
Packit |
5f056f |
|