line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Class::MakeMethods::Template::ClassInherit - Overridable class data |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package MyClass; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Class::MakeMethods( 'Template::ClassInherit:scalar' => 'foo' ); |
10
|
|
|
|
|
|
|
# We now have an accessor method for an "inheritable" scalar value |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package main; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
MyClass->foo( 'Foozle' ); # Set a class-wide value |
15
|
|
|
|
|
|
|
print MyClass->foo(); # Retrieve class-wide value |
16
|
|
|
|
|
|
|
... |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package MySubClass; |
19
|
|
|
|
|
|
|
@ISA = 'MyClass'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
print MySubClass->foo(); # Intially same as superclass, |
22
|
|
|
|
|
|
|
MySubClass->foo('Foobar'); # but overridable per subclass/ |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
The MakeMethods subclass provides accessor methods that search an inheritance tree to find a value. This allows you to set a shared or default value for a given class, and optionally override it in a subclass. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
######################################################################## |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
package Class::MakeMethods::Template::ClassInherit; |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
2
|
|
1739
|
use Class::MakeMethods::Template::Generic '-isasubclass'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
28
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$VERSION = 1.008; |
37
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
62
|
|
38
|
|
|
|
|
|
|
require 5.0; |
39
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
397
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub generic { |
42
|
|
|
|
|
|
|
{ |
43
|
2
|
|
|
2
|
0
|
28
|
'-import' => { |
44
|
|
|
|
|
|
|
'Template::Generic:generic' => '*' |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
'modifier' => { |
47
|
|
|
|
|
|
|
'-all' => [ q{ |
48
|
|
|
|
|
|
|
_INIT_VALUE_CLASS_ |
49
|
|
|
|
|
|
|
* |
50
|
|
|
|
|
|
|
} ], |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
'code_expr' => { |
53
|
|
|
|
|
|
|
'_VALUE_CLASS_' => '$_value_class', |
54
|
|
|
|
|
|
|
'_INIT_VALUE_CLASS_' => q{ |
55
|
|
|
|
|
|
|
my _VALUE_CLASS_; |
56
|
|
|
|
|
|
|
for ( my @_INC_search = _SELF_CLASS_; scalar @_INC_search; ) { |
57
|
|
|
|
|
|
|
_VALUE_CLASS_ = shift @_INC_search; |
58
|
|
|
|
|
|
|
last if ( exists _ATTR_{data}->{_VALUE_CLASS_} ); |
59
|
|
|
|
|
|
|
no strict 'refs'; |
60
|
|
|
|
|
|
|
unshift @_INC_search, @{"_VALUE_CLASS_\::ISA"}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
'_VALUE_' => '_ATTR_{data}->{_VALUE_CLASS_}', |
64
|
|
|
|
|
|
|
'_GET_VALUE_' => q{ _ATTR_{data}->{_VALUE_CLASS_} }, |
65
|
|
|
|
|
|
|
'_SET_VALUE_{}' => q{ ( _VALUE_CLASS_ = _SELF_CLASS_ and _ATTR_{data}->{_VALUE_CLASS_} = * ) }, |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
######################################################################## |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 Standard Methods |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The following methods from Generic should all be supported: |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
scalar |
77
|
|
|
|
|
|
|
string |
78
|
|
|
|
|
|
|
string_index (?) |
79
|
|
|
|
|
|
|
number |
80
|
|
|
|
|
|
|
boolean |
81
|
|
|
|
|
|
|
bits (?) |
82
|
|
|
|
|
|
|
array (*) |
83
|
|
|
|
|
|
|
hash (*) |
84
|
|
|
|
|
|
|
tiedhash (?) |
85
|
|
|
|
|
|
|
hash_of_arrays (?) |
86
|
|
|
|
|
|
|
object (?) |
87
|
|
|
|
|
|
|
instance (?) |
88
|
|
|
|
|
|
|
array_of_objects (?) |
89
|
|
|
|
|
|
|
code (?) |
90
|
|
|
|
|
|
|
code_or_scalar (?) |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See L for the interfaces and behaviors of these method types. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
The items marked with a * above are specifically defined in this package, whereas the others are formed automatically by the interaction of this package's generic settings with the code templates provided by the Generic superclass. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The items marked with a ? above have not been tested sufficiently; please inform the author if they do not function as you would expect. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub array { |
101
|
|
|
|
|
|
|
{ |
102
|
0
|
|
|
0
|
1
|
|
'-import' => { |
103
|
|
|
|
|
|
|
'Template::Generic:array' => '*', |
104
|
|
|
|
|
|
|
}, |
105
|
|
|
|
|
|
|
'modifier' => { |
106
|
|
|
|
|
|
|
'-all' => [ q{ _VALUE_ ||= []; * } ], |
107
|
|
|
|
|
|
|
}, |
108
|
|
|
|
|
|
|
'code_expr' => { |
109
|
|
|
|
|
|
|
'_VALUE_' => '\@{_ATTR_{data}->{_SELF_CLASS_}}', |
110
|
|
|
|
|
|
|
}, |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub hash { |
115
|
|
|
|
|
|
|
{ |
116
|
0
|
|
|
0
|
1
|
|
'-import' => { |
117
|
|
|
|
|
|
|
'Template::Generic:hash' => '*', |
118
|
|
|
|
|
|
|
}, |
119
|
|
|
|
|
|
|
'modifier' => { |
120
|
|
|
|
|
|
|
'-all' => [ q{ _VALUE_ ||= {}; * } ], |
121
|
|
|
|
|
|
|
}, |
122
|
|
|
|
|
|
|
'code_expr' => { |
123
|
|
|
|
|
|
|
'_VALUE_' => '\%{_ATTR_{data}->{_SELF_CLASS_}}', |
124
|
|
|
|
|
|
|
}, |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
######################################################################## |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SEE ALSO |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
See L for general information about this distribution. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
See L for more about this family of subclasses. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
See L for information about the various accessor interfaces subclassed herein. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
If you just need scalar accessors, see L for a very elegant and efficient implementation. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
######################################################################## |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |