1Class::MethodMaker::scaUlsaerr(3C)ontributed Perl DocumeCnltaastsi:o:nMethodMaker::scalar(3)
2
3
4

NAME

6       Class::Method::scalar - Create methods for handling a scalar value.
7

SYNOPSIS

9         package MyClass;
10         use Class::MethodMaker
11           [ scalar => [qw/ a -static s /]];
12
13         sub new {
14           my $class = shift;
15           bless {}, $class;
16         }
17
18         package main;
19
20         my $m = MyClass->new;
21         my $a, $x;
22
23         $a = $m->a;       # *undef*
24         $x = $m->a_isset; # false
25         $a = $m->a(1);    # 1
26         $m->a(3);
27         $x = $m->a_isset; # true
28         $a = $m->a;       # 3
29         $a = $m->a(5);     # 5;
30         $m->a_reset;
31         $x = $m->a_isset; # false
32

DESCRIPTION

34       Creates methods to handle array values in an object.  For a component
35       named "x", by default creates methods "x", "x_reset", "x_isset",
36       "x_clear".
37
38       Methods available are:
39
40       "*"
41
42         $m->a(3);
43         $a = $m->a;       # 3
44         $a = $m->a(5);     # 5;
45
46       Created by default.  If an argument is provided, the component is set
47       to that value.  The method returns the value of the component (after
48       assignment to a provided value, if appropriate).
49
50       *_reset
51
52         $m->a_reset;
53
54       Created by default.  Resets the component back to its default.  Nor‐
55       mally, this means that *_isset will return false, and "*" will return
56       undef.  If "-default" is in effect, then the component will be set to
57       the default value, and *_isset will return true.  If "-default_ctor" is
58       in effect, then the default subr will be invoked, and its return value
59       used to set the value of the component, and *_isset will return true.
60
61       Advanced Note: actually, defaults are assigned as needed: typically,
62       the next time a the value of a component is read.
63
64       *_isset
65
66         print $m->a_isset ? "true" : "false";
67
68       Created by default.  Whether the component is currently set.  This is
69       different from being defined; initially, the component is not set (and
70       if read, will return undef); it can be set to undef (which is a set
71       value, which also returns undef).  Having been set, the only way to
72       unset the component is with <*_reset>.
73
74       If a default value is in effect, then <*_isset> will always return
75       true.
76
77       *_clear
78
79         $m->a(5);
80         $a = $m->a;       # 5
81         $x = $m->a_isset; # true
82         $m->a_clear;
83         $a = $m->a;       # *undef*
84         $x = $m->a_isset; # true
85
86       Created by default.  A shorthand for setting to undef.  Note that the
87       component will be set to undef, not reset, so *_isset will return true.
88
89       *_get
90
91         package MyClass;
92         use Class::MethodMaker
93           [ scalar => [{'*_get' => '*_get'}, 'a'],
94             new    => new, ];
95
96         package main;
97         my $m = MyClass->new;
98         $m->a(3);
99         $a = $m->a_get;     # 3
100         $a = $m->a_get(5);  # 3; ignores argument
101         $a = $m->a_get(5);  # 3; unchanged by previous call
102
103       Created on request.  Retrieves the value of the component without set‐
104       ting (ignores any arguments passed).
105
106       *_set
107
108         package MyClass;
109         use Class::MethodMaker
110           [ scalar => [{'*_set' => '*_set'}, 'a'],
111             new    => new, ];
112
113         package main;
114         my $m = MyClass->new;
115         $m->a(3);
116         $a = $m->a_set;     # *undef*
117         $a = $m->a_set(5);  # *undef*; value is set but not returned
118         $a = $m->a;         # 5
119
120       Created on request.  Sets the component to the first argument (or undef
121       if no argument provided).  Returns no value.
122
123
124
125perl v5.8.8                       2005-11-26     Class::MethodMaker::scalar(3)
Impressum