.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Class::Accessor::Grouped 3pm" .TH Class::Accessor::Grouped 3pm "2011-12-30" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Class::Accessor::Grouped \- Lets you build groups of accessors .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use base \*(AqClass::Accessor::Grouped\*(Aq; \& \& # make basic accessors for objects \& _\|_PACKAGE_\|_\->mk_group_accessors(simple => qw(id name email)); \& \& # make accessor that works for objects and classes \& _\|_PACKAGE_\|_\->mk_group_accessors(inherited => \*(Aqawesome_level\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class lets you build groups of accessors that will call different getters and setters. .SH "METHODS" .IX Header "METHODS" .SS "mk_group_accessors" .IX Subsection "mk_group_accessors" .Vb 1 \& _\|_PACKAGE_\|_\->mk_group_accessors(simple => \*(Aqhair_length\*(Aq, [ hair_color => \*(Aqhc\*(Aq ]); .Ve .ie n .IP "Arguments: $group, @fieldspec" 4 .el .IP "Arguments: \f(CW$group\fR, \f(CW@fieldspec\fR" 4 .IX Item "Arguments: $group, @fieldspec" Returns: none .PP Creates a set of accessors in a given group. .PP \&\f(CW$group\fR is the name of the accessor group for the generated accessors; they will call get_$group($field) on get and set_$group($field, \f(CW$value\fR) on set. .PP If you want to mimic Class::Accessor's mk_accessors \f(CW$group\fR has to be 'simple' to tell Class::Accessor::Grouped to use its own get_simple and set_simple methods. .PP \&\f(CW@fieldspec\fR is a list of field/accessor names; if a fieldspec is a scalar this is used as both field and accessor name, if a listref it is expected to be of the form [ \f(CW$accessor\fR, \f(CW$field\fR ]. .SS "mk_group_ro_accessors" .IX Subsection "mk_group_ro_accessors" .Vb 1 \& _\|_PACKAGE_\|_\->mk_group_ro_accessors(simple => \*(Aqbirthdate\*(Aq, [ social_security_number => \*(Aqssn\*(Aq ]); .Ve .ie n .IP "Arguments: $group, @fieldspec" 4 .el .IP "Arguments: \f(CW$group\fR, \f(CW@fieldspec\fR" 4 .IX Item "Arguments: $group, @fieldspec" Returns: none .PP Creates a set of read only accessors in a given group. Identical to \&\*(L"mk_group_accessors\*(R" but accessors will throw an error if passed a value rather than setting the value. .SS "mk_group_wo_accessors" .IX Subsection "mk_group_wo_accessors" .Vb 1 \& _\|_PACKAGE_\|_\->mk_group_wo_accessors(simple => \*(Aqlie\*(Aq, [ subject => \*(Aqsubj\*(Aq ]); .Ve .ie n .IP "Arguments: $group, @fieldspec" 4 .el .IP "Arguments: \f(CW$group\fR, \f(CW@fieldspec\fR" 4 .IX Item "Arguments: $group, @fieldspec" Returns: none .PP Creates a set of write only accessors in a given group. Identical to \&\*(L"mk_group_accessors\*(R" but accessors will throw an error if not passed a value rather than getting the value. .SS "get_simple" .IX Subsection "get_simple" .ie n .IP "Arguments: $field" 4 .el .IP "Arguments: \f(CW$field\fR" 4 .IX Item "Arguments: $field" Returns: \f(CW$value\fR .PP Simple getter for hash-based objects which returns the value for the field name passed as an argument. .SS "set_simple" .IX Subsection "set_simple" .ie n .IP "Arguments: $field, $new_value" 4 .el .IP "Arguments: \f(CW$field\fR, \f(CW$new_value\fR" 4 .IX Item "Arguments: $field, $new_value" Returns: \f(CW$new_value\fR .PP Simple setter for hash-based objects which sets and then returns the value for the field name passed as an argument. .SS "get_inherited" .IX Subsection "get_inherited" .ie n .IP "Arguments: $field" 4 .el .IP "Arguments: \f(CW$field\fR" 4 .IX Item "Arguments: $field" Returns: \f(CW$value\fR .PP Simple getter for Classes and hash-based objects which returns the value for the field name passed as an argument. This behaves much like Class::Data::Accessor where the field can be set in a base class, inherited and changed in subclasses, and inherited and changed for object instances. .SS "set_inherited" .IX Subsection "set_inherited" .ie n .IP "Arguments: $field, $new_value" 4 .el .IP "Arguments: \f(CW$field\fR, \f(CW$new_value\fR" 4 .IX Item "Arguments: $field, $new_value" Returns: \f(CW$new_value\fR .PP Simple setter for Classes and hash-based objects which sets and then returns the value for the field name passed as an argument. When called on a hash-based object it will set the appropriate hash key value. When called on a class, it will set a class level variable. .PP \&\fBNote:\fR: This method will die if you try to set an object variable on a non hash-based object. .SS "get_component_class" .IX Subsection "get_component_class" .ie n .IP "Arguments: $field" 4 .el .IP "Arguments: \f(CW$field\fR" 4 .IX Item "Arguments: $field" Returns: \f(CW$value\fR .PP Gets the value of the specified component class. .PP .Vb 1 \& _\|_PACKAGE_\|_\->mk_group_accessors(\*(Aqcomponent_class\*(Aq => \*(Aqresult_class\*(Aq); \& \& $self\->result_class\->method(); \& \& ## same as \& $self\->get_component_class(\*(Aqresult_class\*(Aq)\->method(); .Ve .SS "set_component_class" .IX Subsection "set_component_class" .ie n .IP "Arguments: $field, $class" 4 .el .IP "Arguments: \f(CW$field\fR, \f(CW$class\fR" 4 .IX Item "Arguments: $field, $class" Returns: \f(CW$new_value\fR .PP Inherited accessor that automatically loads the specified class before setting it. This method will die if the specified class could not be loaded. .PP .Vb 2 \& _\|_PACKAGE_\|_\->mk_group_accessors(\*(Aqcomponent_class\*(Aq => \*(Aqresult_class\*(Aq); \& _\|_PACKAGE_\|_\->result_class(\*(AqMyClass\*(Aq); \& \& $self\->result_class\->method(); .Ve .SH "INTERNAL METHODS" .IX Header "INTERNAL METHODS" These methods are documented for clarity, but are never meant to be called directly, and are not really meant for overriding either. .SS "get_super_paths" .IX Subsection "get_super_paths" Returns a list of 'parent' or 'super' class names that the current class inherited from. This is what drives the traversal done by \*(L"get_inherited\*(R". .SS "make_group_accessor" .IX Subsection "make_group_accessor" .Vb 2 \& _\|_PACKAGE_\|_\->make_group_accessor(\*(Aqsimple\*(Aq, \*(Aqhair_length\*(Aq, \*(Aqhair_length\*(Aq); \& _\|_PACKAGE_\|_\->make_group_accessor(\*(Aqsimple\*(Aq, \*(Aqhc\*(Aq, \*(Aqhair_color\*(Aq); .Ve .ie n .IP "Arguments: $group, $field, $accessor" 4 .el .IP "Arguments: \f(CW$group\fR, \f(CW$field\fR, \f(CW$accessor\fR" 4 .IX Item "Arguments: $group, $field, $accessor" Returns: \e&accessor_coderef ? .PP Called by mk_group_accessors for each entry in \f(CW@fieldspec\fR. Either returns a coderef which will be installed at \f(CW\*(C`&_\|_PACKAGE_\|_::$accessor\*(C'\fR, or returns \&\f(CW\*(C`undef\*(C'\fR if it elects to install the coderef on its own. .SS "make_group_ro_accessor" .IX Subsection "make_group_ro_accessor" .Vb 2 \& _\|_PACKAGE_\|_\->make_group_ro_accessor(\*(Aqsimple\*(Aq, \*(Aqbirthdate\*(Aq, \*(Aqbirthdate\*(Aq); \& _\|_PACKAGE_\|_\->make_group_ro_accessor(\*(Aqsimple\*(Aq, \*(Aqssn\*(Aq, \*(Aqsocial_security_number\*(Aq); .Ve .ie n .IP "Arguments: $group, $field, $accessor" 4 .el .IP "Arguments: \f(CW$group\fR, \f(CW$field\fR, \f(CW$accessor\fR" 4 .IX Item "Arguments: $group, $field, $accessor" Returns: \e&accessor_coderef ? .PP Called by mk_group_ro_accessors for each entry in \f(CW@fieldspec\fR. Either returns a coderef which will be installed at \f(CW\*(C`&_\|_PACKAGE_\|_::$accessor\*(C'\fR, or returns \&\f(CW\*(C`undef\*(C'\fR if it elects to install the coderef on its own. .SS "make_group_wo_accessor" .IX Subsection "make_group_wo_accessor" .Vb 2 \& _\|_PACKAGE_\|_\->make_group_wo_accessor(\*(Aqsimple\*(Aq, \*(Aqlie\*(Aq, \*(Aqlie\*(Aq); \& _\|_PACKAGE_\|_\->make_group_wo_accessor(\*(Aqsimple\*(Aq, \*(Aqsubj\*(Aq, \*(Aqsubject\*(Aq); .Ve .ie n .IP "Arguments: $group, $field, $accessor" 4 .el .IP "Arguments: \f(CW$group\fR, \f(CW$field\fR, \f(CW$accessor\fR" 4 .IX Item "Arguments: $group, $field, $accessor" Returns: \e&accessor_coderef ? .PP Called by mk_group_wo_accessors for each entry in \f(CW@fieldspec\fR. Either returns a coderef which will be installed at \f(CW\*(C`&_\|_PACKAGE_\|_::$accessor\*(C'\fR, or returns \&\f(CW\*(C`undef\*(C'\fR if it elects to install the coderef on its own. .SH "PERFORMANCE" .IX Header "PERFORMANCE" To provide total flexibility Class::Accessor::Grouped calls methods internally while performing get/set actions, which makes it noticeably slower than similar modules. To compensate, this module will automatically use the insanely fast Class::XSAccessor to generate the \f(CW\*(C`simple\*(C'\fR\-group accessors if this module is available on your system. .SS "Benchmark" .IX Subsection "Benchmark" This is the result of a set/get/set loop benchmark on perl 5.12.1 with thread support, showcasing most popular accessor builders: Moose, Mouse, Moo, \s-1CAF\s0, \s-1CAF_XS\s0, \&\s-1XSA\s0, and \s-1CAF_XSA\s0: .PP .Vb 10 \& Rate CAG moOse CAF moUse moo HANDMADE CAF_XS moUse_XS moo_XS CAF_XSA XSA CAG_XS \& CAG 169/s \-\- \-21% \-24% \-32% \-32% \-34% \-59% \-63% \-67% \-67% \-67% \-67% \& moOse 215/s 27% \-\- \-3% \-13% \-13% \-15% \-48% \-53% \-58% \-58% \-58% \-58% \& CAF 222/s 31% 3% \-\- \-10% \-10% \-13% \-46% \-52% \-57% \-57% \-57% \-57% \& moUse 248/s 46% 15% 11% \-\- \-0% \-3% \-40% \-46% \-52% \-52% \-52% \-52% \& moo 248/s 46% 15% 11% 0% \-\- \-3% \-40% \-46% \-52% \-52% \-52% \-52% \& HANDMADE 255/s 50% 18% 14% 3% 3% \-\- \-38% \-45% \-50% \-51% \-51% \-51% \& CAF_XS 411/s 143% 91% 85% 66% 66% 61% \-\- \-11% \-20% \-20% \-21% \-21% \& moUse_XS 461/s 172% 114% 107% 86% 86% 81% 12% \-\- \-10% \-11% \-11% \-11% \& moo_XS 514/s 204% 139% 131% 107% 107% 102% 25% 12% \-\- \-0% \-1% \-1% \& CAF_XSA 516/s 205% 140% 132% 108% 108% 103% 26% 12% 0% \-\- \-0% \-0% \& XSA 519/s 206% 141% 133% 109% 109% 104% 26% 13% 1% 0% \-\- \-0% \& CAG_XS 519/s 206% 141% 133% 109% 109% 104% 26% 13% 1% 0% 0% \-\- .Ve .PP Benchmark program is available in the root of the repository : .SS "Notes on Class::XSAccessor" .IX Subsection "Notes on Class::XSAccessor" You can force (or disable) the use of Class::XSAccessor before creating a particular \f(CW\*(C`simple\*(C'\fR accessor by either manipulating the global variable \&\f(CW$Class::Accessor::Grouped::USE_XS\fR to true or false (preferably with localization, or you can do so before runtime via the \&\f(CW\*(C`CAG_USE_XS\*(C'\fR environment variable. .PP Since Class::XSAccessor has no knowledge of \*(L"get_simple\*(R" and \&\*(L"set_simple\*(R" this module does its best to detect if you are overriding one of these methods and will fall back to using the perl version of the accessor in order to maintain consistency. However be aware that if you enable use of \f(CW\*(C`Class::XSAccessor\*(C'\fR (automatically or explicitly), create an object, invoke a simple accessor on that object, and \fBthen\fR manipulate the symbol table to install a \f(CW\*(C`get/set_simple\*(C'\fR override \- you get to keep all the pieces. .SH "AUTHORS" .IX Header "AUTHORS" Matt S. Trout .PP Christopher H. Laco .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" Caelum: Rafael Kitover .PP frew: Arthur Axel \*(L"fREW\*(R" Schmidt .PP groditi: Guillermo Roditi .PP Jason Plum .PP ribasushi: Peter Rabbitson .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright (c) 2006\-2010 Matt S. Trout .PP This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.