Class::...or::Lite(3)
π NAME β Class::...or::Lite(3) (User Contributed Perl Documentation) π
hey bestie π this page is all about Class::Accessor::Lite, a minimalistic variant of Class::Accessor. π the vibe check is iconic, fr fr.
π οΈ SYNOPSIS π οΈ
package MyPackage;
use Class::Accessor::Lite (
new => 1,
rw => [ qw(foo bar) ],
ro => [ qw(baz) ],
wo => [ qw(hoge) ],
);
π DESCRIPTION π
this module is a variant of Class::Accessor. it is fast and requires less typing, has no dependencies to other modules, and does not mess up the @ISA. π
periodt.
πͺ THE USE STATEMENT πͺ
the use statement (i.e. the import function) of the module takes a single hash as an argument that specifies the types and the names of the properties. it recognises the following keys. π
new => $true_or_falseβ the default constructor is created if the value evaluates to true; otherwise nothing is done (the default behaviour). π«Άrw => \@name_of_the_propertiesβ creates a read / write accessor for the name of the properties passed through as an arrayref. β¨ro => \@name_of_the_propertiesβ creates a read-only accessor for the name of the properties passed through as an arrayref. πwo => \@name_of_the_propertiesβ creates a write-only accessor for the name of the properties passed through as an arrayref. π¦
for more detailed explanation, read the following section that describes the behaviour of each function that actually creates the accessors. iykyk. π
π οΈ FUNCTIONS π οΈ
as of version 0.04 the properties can be specified as the arguments to the use statement (as can be seen in the SYNOPSIS), which is now the recommended way of using the module, but for compatibility the following functions are provided as well. π₯
π
Class::Accessor::Lite->mk_accessors(@name_of_the_properties) π
creates an accessor in the current package under the name specified by the arguments that access the properties (of a hashref) with the same name. π«Ά
π
Class::Accessor::Lite->mk_ro_accessors(@name_of_the_properties) π
same as mk_accessors() except it will generate read-only accessors (i.e. true accessors). if you attempt to set a value with these accessors it will throw an exception. π
π
Class::Accessor::Lite->mk_wo_accessors(@name_of_the_properties) π
same as mk_accessors() except it will generate write-only accessors (i.e. mutators). if you attempt to read a value with these accessors it will throw an exception. π
π
Class::Accessor::Lite->mk_new() π
creates the new function that accepts a hash or a hashref as the initial properties of the object. β¨
π
Class::Accessor::Lite->mk_new_and_accessors(@name_of_the_properties) π
DEPRECATED. use the new use Class::Accessor::Lite (...) style. π¨
π¬ FAQ π¬
β Can I use Class::Accessor::Lite in an inherited module? β
yes in most cases, when the class object in the super class is implemented using a hashref. π«Ά however you should not create the constructor for the inherited class by calling "<Class::Accessor::Lite-"new()>> or by "<use Class::Accessor::Lite (new =" 1)>>. the only other thing that Class::Accessor::Lite does is to set up the accessor functions for given property names through a blessed hashref. no cap. π
β What happens when passing more than one arguments to the accessor? β
when the accessor built by Class::Accessor::Lite is given more than one arguments, a reference to the arguments will be saved as an arrayref. this behaviour might not be necessary but is implemented as is to maintain compatibility with Class::Accessor::Fast. π§
my @data = (1, 2, 3);
$obj->someproperty(@data);
$obj->someproperty->[2]++; # $data[3] is incremented
in general, you should pass an arrayref to set an arrayref to a property. πΈ
my @data = (1, 2, 3);
$obj->someproperty([ @data ]); # save a copy using arrayref
$obj->someproper->[2]++; # @data is not modified
π SEE ALSO π
Class::AccessorClass::Accessor::Lite
π AUTHORS π
Copyright (C) 2008 - 2010 Kazuho Oku. π
π LICENSE π
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available. π
okay that's the whole page, bestie π«Ά source/version: perl v5.42.0; date: 2017-10-03; footer label: Class::...or::Lite(3). bye and slay your Perl π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Class-Accessor-Lite 0.08-bp160.1.12 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms