.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" 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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' '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 >0, 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. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Class::MethodMaker::scalar 3pm" .TH Class::MethodMaker::scalar 3pm 2024-03-07 "perl v5.38.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::Method::scalar \- Create methods for handling a scalar value. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 3 \& package MyClass; \& use Class::MethodMaker \& [ scalar => [qw/ a \-static s /]]; \& \& sub new { \& my $class = shift; \& bless {}, $class; \& } \& \& package main; \& \& my $m = MyClass\->new; \& my $a, $x; \& \& $a = $m\->a; # *undef* \& $x = $m\->a_isset; # false \& $a = $m\->a(1); # 1 \& $m\->a(3); \& $x = $m\->a_isset; # true \& $a = $m\->a; # 3 \& $a = $m\->a(5); # 5; \& $m\->a_reset; \& $x = $m\->a_isset; # false .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Creates methods to handle array values in an object. For a component named \&\f(CW\*(C`x\*(C'\fR, by default creates methods \f(CW\*(C`x\*(C'\fR, \f(CW\*(C`x_reset\*(C'\fR, \f(CW\*(C`x_isset\*(C'\fR, \f(CW\*(C`x_clear\*(C'\fR. .PP Methods available are: .PP \fR\f(CI\*(C`*\*(C'\fR\fI\fR .IX Subsection "*" .PP .Vb 3 \& $m\->a(3); \& $a = $m\->a; # 3 \& $a = $m\->a(5); # 5; .Ve .PP \&\fICreated by default\fR. If an argument is provided, the component is set to that value. The method returns the value of the component (after assignment to a provided value, if appropriate). .PP \fR\f(CI*_reset\fR\fI\fR .IX Subsection "*_reset" .PP .Vb 1 \& $m\->a_reset; .Ve .PP \&\fICreated by default\fR. Resets the component back to its default. Normally, this means that \f(CW*_isset\fR will return false, and \f(CW\*(C`*\*(C'\fR will return undef. If \&\f(CW\*(C`\-default\*(C'\fR is in effect, then the component will be set to the default value, and \f(CW*_isset\fR will return true. If \f(CW\*(C`\-default_ctor\*(C'\fR is in effect, then the default subr will be invoked, and its return value used to set the value of the component, and \f(CW*_isset\fR will return true. .PP \&\fBAdvanced Note\fR: actually, defaults are assigned as needed: typically, the next time a the value of a component is read. .PP \fR\f(CI*_isset\fR\fI\fR .IX Subsection "*_isset" .PP .Vb 1 \& print $m\->a_isset ? "true" : "false"; .Ve .PP \&\fICreated by default\fR. Whether the component is currently set. This is different from being defined; initially, the component is not set (and if read, will return undef); it can be set to undef (which is a set value, which also returns undef). Having been set, the only way to unset the component is with <*_reset>. .PP If a default value is in effect, then <*_isset> will always return true. .PP \fR\f(CI*_clear\fR\fI\fR .IX Subsection "*_clear" .PP .Vb 6 \& $m\->a(5); \& $a = $m\->a; # 5 \& $x = $m\->a_isset; # true \& $m\->a_clear; \& $a = $m\->a; # *undef* \& $x = $m\->a_isset; # true .Ve .PP \&\fICreated by default\fR. A shorthand for setting to undef. Note that the component will be set to undef, not reset, so \f(CW*_isset\fR will return true. .PP \fR\f(CI*_get\fR\fI\fR .IX Subsection "*_get" .PP .Vb 4 \& package MyClass; \& use Class::MethodMaker \& [ scalar => [{\*(Aq*_get\*(Aq => \*(Aq*_get\*(Aq}, \*(Aqa\*(Aq], \& new => new, ]; \& \& package main; \& my $m = MyClass\->new; \& $m\->a(3); \& $a = $m\->a_get; # 3 \& $a = $m\->a_get(5); # 3; ignores argument \& $a = $m\->a_get(5); # 3; unchanged by previous call .Ve .PP \&\fICreated on request\fR. Retrieves the value of the component without setting (ignores any arguments passed). .PP \fR\f(CI*_set\fR\fI\fR .IX Subsection "*_set" .PP .Vb 4 \& package MyClass; \& use Class::MethodMaker \& [ scalar => [{\*(Aq*_set\*(Aq => \*(Aq*_set\*(Aq}, \*(Aqa\*(Aq], \& new => new, ]; \& \& package main; \& my $m = MyClass\->new; \& $m\->a(3); \& $a = $m\->a_set; # *undef* \& $a = $m\->a_set(5); # *undef*; value is set but not returned \& $a = $m\->a; # 5 .Ve .PP \&\fICreated on request\fR. Sets the component to the first argument (or undef if no argument provided). Returns no value.