1Class::Accessor::GroupeUds(e3r)Contributed Perl DocumentCaltaisosn::Accessor::Grouped(3)
2
3
4

NAME

6       Class::Accessor::Grouped - Lets you build groups of accessors
7

SYNOPSIS

DESCRIPTION

10       This class lets you build groups of accessors that will call different
11       getters and setters.
12

METHODS

14   mk_group_accessors
15       Arguments: $group, @fieldspec
16           Returns: none
17
18       Creates a set of accessors in a given group.
19
20       $group is the name of the accessor group for the generated accessors;
21       they will call get_$group($field) on get and set_$group($field, $value)
22       on set.
23
24       If you want to mimic Class::Accessor's mk_accessors $group has to be
25       'simple' to tell Class::Accessor::Grouped to use its own get_simple and
26       set_simple methods.
27
28       @fieldspec is a list of field/accessor names; if a fieldspec is a
29       scalar this is used as both field and accessor name, if a listref it is
30       expected to be of the form [ $accessor, $field ].
31
32   mk_group_ro_accessors
33       Arguments: $group, @fieldspec
34           Returns: none
35
36       Creates a set of read only accessors in a given group. Identical to
37       "mk_group_accessors" but accessors will throw an error if passed a
38       value rather than setting the value.
39
40   mk_group_wo_accessors
41       Arguments: $group, @fieldspec
42           Returns: none
43
44       Creates a set of write only accessors in a given group. Identical to
45       "mk_group_accessors" but accessors will throw an error if not passed a
46       value rather than getting the value.
47
48   make_group_accessor
49       Arguments: $group, $field, $method
50           Returns: \&accessor_coderef ?
51
52       Called by mk_group_accessors for each entry in @fieldspec. Either
53       returns a coderef which will be installed at "&__PACKAGE__::$method",
54       or returns "undef" if it elects to install the coderef on its own.
55
56   make_group_ro_accessor
57       Arguments: $group, $field, $method
58           Returns: \&accessor_coderef ?
59
60       Called by mk_group_ro_accessors for each entry in @fieldspec. Either
61       returns a coderef which will be installed at "&__PACKAGE__::$method",
62       or returns "undef" if it elects to install the coderef on its own.
63
64   make_group_wo_accessor
65       Arguments: $group, $field, $method
66           Returns: \&accessor_coderef ?
67
68       Called by mk_group_wo_accessors for each entry in @fieldspec. Either
69       returns a coderef which will be installed at "&__PACKAGE__::$method",
70       or returns "undef" if it elects to install the coderef on its own.
71
72   get_simple
73       Arguments: $field
74           Returns: $value
75
76       Simple getter for hash-based objects which returns the value for the
77       field name passed as an argument.
78
79   set_simple
80       Arguments: $field, $new_value
81           Returns: $new_value
82
83       Simple setter for hash-based objects which sets and then returns the
84       value for the field name passed as an argument.
85
86   get_inherited
87       Arguments: $field
88           Returns: $value
89
90       Simple getter for Classes and hash-based objects which returns the
91       value for the field name passed as an argument. This behaves much like
92       Class::Data::Accessor where the field can be set in a base class,
93       inherited and changed in subclasses, and inherited and changed for
94       object instances.
95
96   set_inherited
97       Arguments: $field, $new_value
98           Returns: $new_value
99
100       Simple setter for Classes and hash-based objects which sets and then
101       returns the value for the field name passed as an argument. When called
102       on a hash-based object it will set the appropriate hash key value. When
103       called on a class, it will set a class level variable.
104
105       Note:: This method will die if you try to set an object variable on a
106       non hash-based object.
107
108   get_component_class
109       Arguments: $field
110           Returns: $value
111
112       Gets the value of the specified component class.
113
114           __PACKAGE__->mk_group_accessors('component_class' => 'result_class');
115
116           $self->result_class->method();
117
118           ## same as
119           $self->get_component_class('result_class')->method();
120
121   set_component_class
122       Arguments: $field, $class
123           Returns: $new_value
124
125       Inherited accessor that automatically loads the specified class before
126       setting it. This method will die if the specified class could not be
127       loaded.
128
129           __PACKAGE__->mk_group_accessors('component_class' => 'result_class');
130           __PACKAGE__->result_class('MyClass');
131
132           $self->result_class->method();
133
134   get_super_paths
135       Returns a list of 'parent' or 'super' class names that the current
136       class inherited from.
137

PERFORMANCE

139       To provide total flexibility Class::Accessor::Grouped calls methods
140       internally while performing get/set actions, which makes it noticeably
141       slower than similar modules. To compensate, this module will
142       automatically use the insanely fast Class::XSAccessor to generate the
143       "simple"-group accessors, if Class::XSAccessor >= 1.06 is available on
144       your system.
145
146   Benchmark
147       This is the result of a set/get/set loop benchmark on perl 5.12.1 with
148       thread support, showcasing most popular accessor builders: Moose,
149       Mouse, CAF, CAF_XS and XSA:
150
151                   Rate     CAG   moOse     CAF HANDMADE  CAF_XS moUse_XS CAG_XS     XSA
152        CAG      1777/s      --    -27%    -29%     -36%    -62%     -67%   -72%    -73%
153        moOse    2421/s     36%      --     -4%     -13%    -48%     -55%   -61%    -63%
154        CAF      2511/s     41%      4%      --     -10%    -47%     -53%   -60%    -61%
155        HANDMADE 2791/s     57%     15%     11%       --    -41%     -48%   -56%    -57%
156        CAF_XS   4699/s    164%     94%     87%      68%      --     -13%   -25%    -28%
157        moUse_XS 5375/s    203%    122%    114%      93%     14%       --   -14%    -18%
158        CAG_XS   6279/s    253%    159%    150%     125%     34%      17%     --     -4%
159        XSA      6515/s    267%    169%    159%     133%     39%      21%     4%      --
160
161       Benchmark program is available in the root of the repository
162       <http://search.cpan.org/dist/Class-Accessor-Grouped/>:
163
164   Notes on Class::XSAccessor
165       You can force (or disable) the use of Class::XSAccessor before creating
166       a particular "simple" accessor by either manipulating the global
167       variable $Class::Accessor::Grouped::USE_XS to true or false (preferably
168       with localization, or you can do so before runtime via the "CAG_USE_XS"
169       environment variable.
170
171       Since Class::XSAccessor has no knowledge of "get_simple" and
172       "set_simple" this module does its best to detect if you are overriding
173       one of these methods and will fall back to using the perl version of
174       the accessor in order to maintain consistency. However be aware that if
175       you enable use of "Class::XSAccessor" (automatically or explicitly),
176       create an object, invoke a simple accessor on that object, and then
177       manipulate the symbol table to install a "get/set_simple" override -
178       you get to keep all the pieces.
179
180       While Class::XSAccessor works surprisingly well for the amount of black
181       magic it tries to pull off, it's still black magic. At present (Sep
182       2010) the module is known to have problems on Windows under heavy
183       thread-stress (e.g. Win32+Apache+mod_perl). Thus for the time being
184       Class::XSAccessor will not be used automatically if you are running
185       under "MSWin32".
186

AUTHORS

188       Matt S. Trout <mst@shadowcatsystems.co.uk>
189
190       Christopher H. Laco <claco@chrislaco.com>
191

CONTRIBUTORS

193       Caelum: Rafael Kitover <rkitover@cpan.org>
194
195       groditi: Guillermo Roditi <groditi@cpan.org>
196
197       Jason Plum <jason.plum@bmmsi.com>
198
199       ribasushi: Peter Rabbitson <ribasushi@cpan.org>
200
202       Copyright (c) 2006-2010 Matt S. Trout <mst@shadowcatsystems.co.uk>
203
204       This program is free software; you can redistribute it and/or modify it
205       under the same terms as perl itself.
206
207
208
209perl v5.12.2                      2010-10-11       Class::Accessor::Grouped(3)
Impressum