1MakeMethods::Template::UCslearssCVoanrt(r3i)buted Perl DMoackuemMeentthaotdiso:n:Template::ClassVar(3)
2
3
4
6 Class::MakeMethods::Template::ClassVar - Static methods with subclass
7 variation
8
10 package MyObject;
11 use Class::MakeMethods::Template::ClassVar (
12 scalar => [ 'foo' ]
13 );
14
15 package main;
16
17 MyObject->foo('bar')
18 print MyObject->foo();
19
20 $MyObject::foo = 'bazillion';
21 print MyObject->foo();
22
24 These meta-methods provide access to package (class global) variables,
25 with the package determined at run-time.
26
27 This is basically the same as the PackageVar meta-methods, except that
28 PackageVar methods find the named variable in the package that defines
29 the method, while ClassVar methods use the package the object is
30 blessed into. As a result, subclasses will each store a distinct value
31 for a ClassVar method, but will share the same value for a PackageVar
32 or Static method.
33
34 Common Parameters: The following parameters are defined for ClassVar
35 meta-methods.
36
37 variable
38 The name of the variable to store the value in. Defaults to the
39 same name as the method.
40
41 Standard Methods
42 The following methods from Generic should all be supported:
43
44 scalar
45 string
46 string_index (?)
47 number
48 boolean
49 bits (?)
50 array (*)
51 hash (*)
52 tiedhash (?)
53 hash_of_arrays (?)
54 object (?)
55 instance (?)
56 array_of_objects (?)
57 code (?)
58 code_or_scalar (?)
59
60 See Class::MakeMethods::Template::Generic for the interfaces and
61 behaviors of these method types.
62
63 The items marked with a * above are specifically defined in this
64 package, whereas the others are formed automatically by the interaction
65 of this package's generic settings with the code templates provided by
66 the Generic superclass.
67
68 The items marked with a ? above have not been tested sufficiently;
69 please inform the author if they do not function as you would expect.
70
71 vars
72 This rewrite rule converts package variable names into ClassVar methods
73 of the equivalent data type.
74
75 Here's an example declaration:
76
77 package MyClass;
78
79 use Class::MakeMethods::Template::ClassVar (
80 vars => '$VERSION @ISA'
81 );
82
83 MyClass now has methods that get and set the contents of its
84 $MyClass::VERSION and @MyClass::ISA package variables:
85
86 MyClass->VERSION( 2.4 );
87 MyClass->push_ISA( 'Exporter' );
88
89 Subclasses can use these methods to adjust their own variables:
90
91 package MySubclass;
92 MySubclass->MyClass::push_ISA( 'MyClass' );
93 MySubclass->VERSION( 1.0 );
94
95
96
97perl v5.32.0 2020-07-28MakeMethods::Template::ClassVar(3)