1Class::Accessor::Lite(3U)ser Contributed Perl DocumentatiColnass::Accessor::Lite(3)
2
3
4

NAME

6       Class::Accessor::Lite - a minimalistic variant of Class::Accessor
7

SYNOPSIS

9           package MyPackage;
10
11           use Class::Accessor::Lite (
12               new => 1,
13               rw  => [ qw(foo bar) ],
14               ro  => [ qw(baz) ],
15               wo  => [ qw(hoge) ],
16           );
17

DESCRIPTION

19       The module is a variant of "Class::Accessor".  It is fast and requires
20       less typing, has no dependencies to other modules, and does not mess up
21       the @ISA.
22

THE USE STATEMENT

24       The use statement (i.e. the "import" function) of the module takes a
25       single hash as an argument that specifies the types and the names of
26       the properties.  Recognises the following keys.
27
28       new => $true_or_false
29           the default constructor is created if the value evaluates to true,
30           otherwise nothing is done (the default behaviour)
31
32       rw => \@name_of_the_properties
33           creates a read / write accessor for the name of the properties
34           passed through as an arrayref
35
36       ro => \@name_of_the_properties
37           creates a read-only accessor for the name of the properties passed
38           through as an arrayref
39
40       wo => \@name_of_the_properties
41           creates a write-only accessor for the name of the properties passed
42           through as an arrayref
43
44       For more detailed explanation read the following section describing the
45       behaviour of each function that actually creates the accessors.
46

FUNCTIONS

48       As of version 0.04 the properties can be specified as the arguments to
49       the "use" statement (as can be seen in the SYNOPSIS) which is now the
50       recommended way of using the module, but for compatibility the
51       following functions are provided as well.
52
53   Class::Accessor::Lite->mk_accessors(@name_of_the_properties)
54       Creates an accessor in current package under the name specified by the
55       arguments that access the properties (of a hashref) with the same name.
56
57   Class::Accessor::Lite->mk_ro_accessors(@name_of_the_properties)
58       Same as mk_accessors() except it will generate read-only accessors
59       (i.e. true accessors).  If you attempt to set a value with these
60       accessors it will throw an exception.
61
62   Class::Accessor::Lite->mk_wo_accessors(@name_of_the_properties)
63       Same as mk_accessors() except it will generate write-only accessors
64       (i.e. mutators).  If you attempt to read a value with these accessors
65       it will throw an exception.
66
67   Class::Accessor::Lite->mk_new()
68       Creates the "new" function that accepts a hash or a hashref as the
69       initial properties of the object.
70
71   Class::Accessor::Lite->mk_new_and_accessors(@name_of_the_properties)
72       DEPRECATED.  Use the new "use Class::Accessor::Lite (...)" style.
73

FAQ

75   Can I use "Class::Accessor::Lite" in an inherited module?
76       Yes in most cases, when the class object in the super class is
77       implemented using a hashref.  However you _should_ _not_ create the
78       constructor for the inherited class by calling
79       "<Class::Accessor::Lite-"new()>> or by "<use Class::Accessor::Lite (new
80       =" 1)>>.  The only other thing that "Class::Accessor::Lite" does is to
81       set up the accessor functions for given property names through a
82       blessed hashref.
83
84   What happens when passing more than one arguments to the accessor?
85       When the accessor built by Class::Accessor::Lite is given more than one
86       arguments, a reference to the arguments will be saved as an arrayref.
87       This behaviour might not be necessary but is implemented as is to
88       maintain compatibility with Class::Accessor::Fast.
89
90           my @data = (1, 2, 3);
91           $obj->someproperty(@data);
92
93           $obj->someproperty->[2]++; # $data[3] is incremented
94
95       In general, you should pass an arrayref to set an arrayref to a
96       property.
97
98           my @data = (1, 2, 3);
99           $obj->someproperty([ @data ]); # save a copy using arrayref
100
101           $obj->someproper->[2]++; # @data is not modified
102

SEE ALSO

104       Class::Accessor
105
106       Class::Accessor::Lite
107

AUTHORS

109       Copyright (C) 2008 - 2010 Kazuho Oku
110

LICENSE

112       This library is free software; you can redistribute it and/or modify it
113       under the same terms as Perl itself, either Perl version 5.8.6 or, at
114       your option, any later version of Perl 5 you may have available.
115
116
117
118perl v5.38.0                      2023-07-20          Class::Accessor::Lite(3)
Impressum