blib/lib/Class/MakeMethods/Template/ClassInherit.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 66.6% 2 / 3 totaltotal 79.1% 19 / 24 CC 1 SCAR 2.9
CC
1
Cov
87%
array
2.0
hash
2.0
BEGIN
1.0
CRAP 1.3
« blib/lib/Class/MakeMethods/Emulator/mcoder.pm ↑ Summary blib/lib/Class/MakeMethods/Template/Inheritable.pm »
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 ▶use Class::MakeMethods::Template::Generic '-isasubclass';
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 2 $VERSION = 1.008;
37 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 require 5.0;
39 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 2 ▶sub generic {
Subroutine generic: called CC=1 SCAR=0.0
Pod undocumented
42 {
43 2 '-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<Class::MakeMethods::Template::Generic> 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 0 ▶sub array {
Subroutine array: not called CC=1 SCAR=6.9
Pod documented
101 {
102 0 '-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 0 ▶sub hash {
Subroutine hash: not called CC=1 SCAR=6.9
Pod documented
115 {
116 0 '-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<Class::MakeMethods> for general information about this distribution.
133  
134 See L<Class::MakeMethods::Template> for more about this family of subclasses.
135  
136 See L<Class::MakeMethods::Template::Generic> for information about the various accessor interfaces subclassed herein.
137  
138 If you just need scalar accessors, see L<Class::Data::Inheritable> for a very elegant and efficient implementation.
139  
140 =cut
141  
142 ########################################################################
143  
144 2 1;
« blib/lib/Class/MakeMethods/Emulator/mcoder.pm ↑ Summary blib/lib/Class/MakeMethods/Template/Inheritable.pm »