06 Dec 2010 07:04:36 UTC
- Distribution: Class-Accessor-Lite
- Module version: 0.05
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (4)
- Testers (5990 / 2 / 0)
- KwaliteeBus factor: 0
- License: perl_5
- Activity24 month
- Download (27.33KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:4 non-PAUSE usersKAZUHO Kazuho Okuand 1 contributors
- Copyright (C) 2008 - 2010 Kazuho Oku
- THE USE STATEMENT
- SEE ALSO
Class::Accessor::Lite - a minimalistic variant of Class::Accessor
package MyPackage; use Class::Accessor::Lite ( new => 1, rw => [ qw(foo bar) ], ro => [ qw(baz) ], wo => [ qw(hoge) ], );
The 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.
The use statement (i.e. the
importfunction) of the module takes a single hash as an argument that specifies the types and the names of the properties. 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 write-only accessor for the name of the properties passed through as an arrayref
- rw => \@name_of_the_properties
creates a read-only accessor for the name of the properties passed through as an arrayref
For more detailed explanation read the following section describing the behaviour of each function that actually creates the accessors.
As of version 0.04 the properties can be specified as the arguments to the
usestatement (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.
Creates an accessor in current package under the name specified by the arguments that access the properties (of a hashref) with the same name.
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.
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.
newfunction that accepts a hash or a hashref as the initial properties of the object.
DEPRECATED. Use the new "use Class::Accessor::Lite (...)" style.
Yes in most cases, when the class object in the super class is implemeted 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::Litedoes is to set up the accessor functions for given property names through a blessed hashref.
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->++; # $data 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->++; # @data is not modified
Copyright (C) 2008 - 2010 Kazuho Oku
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.
Module Install Instructions
To install Class::Accessor::Lite, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Class::Accessor::Lite
For more information on module installation, please visit the detailed CPAN module installation guide.