Debian Codegraph @

README

raw
1 NAME
2 Class::Accessor::Lite - a minimalistic variant of Class::Accessor
3
4 SYNOPSIS
5 package MyPackage;
6
7 use Class::Accessor::Lite (
8 new => 1,
9 rw => [ qw(foo bar) ],
10 ro => [ qw(baz) ],
11 wo => [ qw(hoge) ],
12 );
13
14 DESCRIPTION
15 The module is a variant of "Class::Accessor". It is fast and requires
16 less typing, has no dependencies to other modules, and does not mess up
17 the @ISA.
18
19 THE USE STATEMENT
20 The use statement (i.e. the "import" function) of the module takes a
21 single hash as an argument that specifies the types and the names of the
22 properties. Recognises the following keys.
23
24 new => $true_or_false
25 the default constructor is created if the value evaluates to true,
26 otherwise nothing is done (the default behaviour)
27
28 rw => \@name_of_the_properties
29 creates a read / write accessor for the name of the properties
30 passed through as an arrayref
31
32 ro => \@name_of_the_properties
33 creates a read-only accessor for the name of the properties passed
34 through as an arrayref
35
36 wo => \@name_of_the_properties
37 creates a write-only accessor for the name of the properties passed
38 through as an arrayref
39
40 For more detailed explanation read the following section describing the
41 behaviour of each function that actually creates the accessors.
42
43 FUNCTIONS
44 As of version 0.04 the properties can be specified as the arguments to
45 the "use" statement (as can be seen in the SYNOPSIS) which is now the
46 recommended way of using the module, but for compatibility the following
47 functions are provided as well.
48
49 Class::Accessor::Lite->mk_accessors(@name_of_the_properties)
50 Creates an accessor in current package under the name specified by the
51 arguments that access the properties (of a hashref) with the same name.
52
53 Class::Accessor::Lite->mk_ro_accessors(@name_of_the_properties)
54 Same as mk_accessors() except it will generate read-only accessors (i.e.
55 true accessors). If you attempt to set a value with these accessors it
56 will throw an exception.
57
58 Class::Accessor::Lite->mk_wo_accessors(@name_of_the_properties)
59 Same as mk_accessors() except it will generate write-only accessors
60 (i.e. mutators). If you attempt to read a value with these accessors it
61 will throw an exception.
62
63 Class::Accessor::Lite->mk_new()
64 Creates the "new" function that accepts a hash or a hashref as the
65 initial properties of the object.
66
67 Class::Accessor::Lite->mk_new_and_accessors(@name_of_the_properties)
68 DEPRECATED. Use the new "use Class::Accessor::Lite (...)" style.
69
70 FAQ
71 Can I use "Class::Accessor::Lite" in an inherited module?
72 Yes in most cases, when the class object in the super class is
73 implemented using a hashref. However you _should_ _not_ create the
74 constructor for the inherited class by calling
75 "<Class::Accessor::Lite-"new()>> or by "<use Class::Accessor::Lite (new
76 =" 1)>>. The only other thing that "Class::Accessor::Lite" does is to
77 set up the accessor functions for given property names through a blessed
78 hashref.
79
80 What happens when passing more than one arguments to the accessor?
81 When the accessor built by Class::Accessor::Lite is given more than one
82 arguments, a reference to the arguments will be saved as an arrayref.
83 This behaviour might not be necessary but is implemented as is to
84 maintain compatibility with Class::Accessor::Fast.
85
86 my @data = (1, 2, 3);
87 $obj->someproperty(@data);
88
89 $obj->someproperty->[2]++; # $data[3] is incremented
90
91 In general, you should pass an arrayref to set an arrayref to a
92 property.
93
94 my @data = (1, 2, 3);
95 $obj->someproperty([ @data ]); # save a copy using arrayref
96
97 $obj->someproper->[2]++; # @data is not modified
98
99 SEE ALSO
100 Class::Accessor
101
102 Class::Accessor::Lite
103
104 AUTHORS
105 Copyright (C) 2008 - 2010 Kazuho Oku
106
107 LICENSE
108 This library is free software; you can redistribute it and/or modify it
109 under the same terms as Perl itself, either Perl version 5.8.6 or, at
110 your option, any later version of Perl 5 you may have available.
111