Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

class::methodmaker::scalar(3pm) [debian man page]

Class::MethodMaker::scalar(3pm) 			User Contributed Perl Documentation			   Class::MethodMaker::scalar(3pm)

NAME
Class::Method::scalar - Create methods for handling a scalar value. SYNOPSIS
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 DESCRIPTION
Creates methods to handle array values in an object. For a component named "x", by default creates methods "x", "x_reset", "x_isset", "x_clear". Methods available are: "*" $m->a(3); $a = $m->a; # 3 $a = $m->a(5); # 5; Created by default. 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). *_reset $m->a_reset; Created by default. Resets the component back to its default. Normally, this means that *_isset will return false, and "*" will return undef. If "-default" is in effect, then the component will be set to the default value, and *_isset will return true. If "-default_ctor" is in effect, then the default subr will be invoked, and its return value used to set the value of the component, and *_isset will return true. Advanced Note: actually, defaults are assigned as needed: typically, the next time a the value of a component is read. *_isset print $m->a_isset ? "true" : "false"; Created by default. 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>. If a default value is in effect, then <*_isset> will always return true. *_clear $m->a(5); $a = $m->a; # 5 $x = $m->a_isset; # true $m->a_clear; $a = $m->a; # *undef* $x = $m->a_isset; # true Created by default. A shorthand for setting to undef. Note that the component will be set to undef, not reset, so *_isset will return true. *_get package MyClass; use Class::MethodMaker [ scalar => [{'*_get' => '*_get'}, 'a'], 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 Created on request. Retrieves the value of the component without setting (ignores any arguments passed). *_set package MyClass; use Class::MethodMaker [ scalar => [{'*_set' => '*_set'}, 'a'], 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 Created on request. Sets the component to the first argument (or undef if no argument provided). Returns no value. perl v5.14.2 2011-11-15 Class::MethodMaker::scalar(3pm)

Check Out this Related Man Page

Class::MethodMaker::V1Compat(3) 			User Contributed Perl Documentation			   Class::MethodMaker::V1Compat(3)

NAME
Class::MethodMaker::V1Compat - V1 compatibility code for C::MM SYNOPSIS
This class is for internal implementation only. It is not a public API. DESCRIPTION
Class::MethodMaker version 2 strives for backward-compatiblity with version 1 as far as possible. That is to say, classes built with version 1 should work with few if any changes. However, the calling conventions for building new classes are significantly different: this is necessary to achieve a greater consistency of arguments. Version 2 takes all arguments within a single arrayref: use Class::MethodMaker [ scalar => 'a' ]; If arguments are presented as a list, then Class::MethodMaker assumes that this is a version 1 call, and acts accordingly. Version 1 arguments are passed and internally rephrased to version 2 arguments, and passed off to the version 2 engine. Thus, the majority of version 1 calls can be upgraded to version 2 merely by rephrasing. However, there are a number of behaviours that in version 1 that are internally inconsistent. These behaviours are mimicked in version 1 mode as far as possible, but are not reproducible in version 2 (to allow version 2 clients to rely on a more internally consistent interface). Version 2 Implementations The nearest equivalent to each 1 component (slot) available in version 2 is shown below using the indicated data-structures & options to create a component called "a" that mimicks the V1 component behaviour as closely as possible: abstract use Class::MethodMaker [ abstract => 'a' ]; boolean Boolean is available as a backwards compatiblity hack, but there is currently no V2 equivalent. It is likely that some replacement mechanism will be introduced in the future, but that it will be incompatible with the version 1 boolean. code use Class::MethodMaker [ scalar => 'a' ]; Let's face it, the v1 store-if-it's-a-coderef-else-retrieve semantics are rather broken. How do you pass a coderef as argument to one of these? It is on the TODO list to recognize code as fundamental restricted type (analogous to INTEGER), which would add in a *_invoke method. copy use Class::MethodMaker [ copy => 'a' ]; The v2 method is the same as v1. counter use Class::MethodMaker [ scalar => [{-type => Class::MethodMaker::Constants::INTEGER}, 'a'] ]; copy deep_copy use Class::MethodMaker [ copy => [ -deep => 'a' ] ]; get_concat use Class::MethodMaker [ scalar => [{ -store_cb => sub { defined $_[1] ? ( defined $_[3] ? "$_[3] $_[1]" : $_[1] ) : undef; } }, 'a' ] ]; get_set use Class::MethodMaker [ scalar => 'a' ]; hash use Class::MethodMaker [ hash => 'a' ]; key_attrib Although v1 calls will continue to work, this is not supported in v2. key_with_create Although v1 calls will continue to work, this is not supported in v2. list use Class::MethodMaker [ list => 'a' ]; Note that the "*" method now sets the whole array if given arguments. method See "code". new use Class::MethodMaker [ new => 'a' ]; new_hash_init use Class::MethodMaker [ new => [ -hash => 'a' ] ]; new_hash_with_init use Class::MethodMaker [ new => [ -hash => -init => 'a' ] ]; new_with_args Although v1 calls will continue to work, this is not supported in v2, for it is a trivial application of "new_with_init". new_with_init use Class::MethodMaker [ new => [ -init => 'a' ] ]; object use Class::MethodMaker [ scalar => [{ -type => 'MyClass', -forward => [qw/ method1 method2 /] }, 'a' ] ]; object_tie_hash use Class::MethodMaker [ hash => [{ -type => 'MyClass', -forward => [qw/ method1 method2 /], -tie_class => 'Tie::MyTie', -tie_args => [qw/ foo bar baz /], }, 'a' ] ]; object_tie_list use Class::MethodMaker [ array => [{ -type => 'MyClass', -forward => [qw/ method1 method2 /], -tie_class => 'Tie::MyTie', -tie_args => [qw/ foo bar baz /], }, 'a' ] ]; set_once use Class::MethodMaker [ scalar => [{ -store_cb => sub { die "Already stored $_[3]" if @_ > 3; } }, 'a' ] ]; set_once_static use Class::MethodMaker [ scalar => [{ -store_cb => sub { die "Already stored $_[3]" if @_ > 3; }, -static => 1, }, 'a' ] ]; singleton use Class::MethodMaker [ new => [ -singleton => -hash => -init => 'a' ] ]; static_get_set use Class::MethodMaker [ scalar => [ -static => 'a' ], ]; static_hash use Class::MethodMaker [ hash => [ -static => 'a' ], ]; static_list use Class::MethodMaker [ list => [ -static => 'a' ], ]; tie_hash use Class::MethodMaker [ hash => [ { -tie_class => 'MyTie', -tie_args => [qw/ foo bar baz /], } => 'a' ], ]; tie_list use Class::MethodMaker [ array => [ { -tie_class => 'MyTie', -tie_args => [qw/ foo bar baz /], } => 'a' ], ]; tie_scalar use Class::MethodMaker [ scalar => [ { -tie_class => 'MyTie', -tie_args => [qw/ foo bar baz /], } => 'a' ], ]; Caveats & Expected Breakages The following version 1 component (slot) types are not currently supported in version 2: grouped_fields hash_of_lists listed_attrib struct EXAMPLES
BUGS
REPORTING BUGS
Email the development mailing list "class-mmaker-devel@lists.sourceforge.net". AUTHOR
Martyn J. Pearce COPYRIGHT
Copyright (c) 2003, 2004 Martyn J. Pearce. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perl v5.12.1 2008-12-03 Class::MethodMaker::V1Compat(3)
Man Page

Featured Tech Videos