1MakeMethods::Emulator::UIsnehrerCiotnatbrlieb(u3t)ed PerMlakDeoMceutmheondtsa:t:iEomnulator::Inheritable(3)
2
3
4
6 Class::MakeMethods::Emulator::Inheritable - Emulate Class::Inheritable
7
9 package Stuff;
10 use base qw(Class::MakeMethods::Emulator::Inheritable);
11
12 # Set up DataFile as inheritable class data.
13 Stuff->mk_classdata('DataFile');
14
15 # Declare the location of the data file for this class.
16 Stuff->DataFile('/etc/stuff/data');
17
19 This module is an adaptor that provides emulatation of
20 Class::Data::Inheritable by invoking similiar functionality provided by
21 Class::MakeMethods::ClassInherit.
22
23 The public interface provided by Class::MakeMethods::Emulator::Inheri‐
24 table is identical to that of Class::Data::Inheritable.
25
26 Class::Data::Inheritable is for creating accessor/mutators to class
27 data. That is, if you want to store something about your class as a
28 whole (instead of about a single object). This data is then inherited
29 by your subclasses and can be overriden.
30
32 As specified by Class::Data::Inheritable, clients should inherit from
33 this module and then invoke the mk_classdata() method for each class
34 method desired:
35
36 Class->mk_classdata($data_accessor_name);
37
38 This is a class method used to declare new class data accessors. A new
39 accessor will be created in the Class using the name from $data_acces‐
40 sor_name.
41
42 Class->mk_classdata($data_accessor_name, $initial_value);
43
44 You may also pass a second argument to initialize the value.
45
46 To facilitate overriding, mk_classdata creates an alias to the acces‐
47 sor, _field_accessor(). So Suitcase() would have an alias _Suit‐
48 case_accessor() that does the exact same thing as Suitcase(). This is
49 useful if you want to alter the behavior of a single accessor yet still
50 get the benefits of inheritable class data. For example.
51
52 sub Suitcase {
53 my($self) = shift;
54 warn "Fashion tragedy" if @_ and $_[0] eq 'Plaid';
55
56 $self->_Suitcase_accessor(@_);
57 }
58
60 Note that the internal implementation of Class::MakeMethods::ClassIn‐
61 herit does not match that of Class::Data::Inheritable. In particular,
62 Class::Data::Inheritable installs new methods in subclasses when they
63 first initialize their value, while
64
66 The example provided by Class::Data::Inheritable is equally applicable
67 to this emulator.
68
69 package Pere::Ubu;
70 use base qw(Class::MakeMethods::Emulator::Inheritable);
71 Pere::Ubu->mk_classdata('Suitcase');
72
73 will generate the method Suitcase() in the class Pere::Ubu.
74
75 This new method can be used to get and set a piece of class data.
76
77 Pere::Ubu->Suitcase('Red');
78 $suitcase = Pere::Ubu->Suitcase;
79
80 The interesting part happens when a class inherits from Pere::Ubu:
81
82 package Raygun;
83 use base qw(Pere::Ubu);
84
85 # Raygun's suitcase is Red.
86 $suitcase = Raygun->Suitcase;
87
88 Raygun inherits its Suitcase class data from Pere::Ubu.
89
90 Inheritance of class data works analgous to method inheritance. As
91 long as Raygun does not "override" its inherited class data (by using
92 Suitcase() to set a new value) it will continue to use whatever is set
93 in Pere::Ubu and inherit further changes:
94
95 # Both Raygun's and Pere::Ubu's suitcases are now Blue
96 Pere::Ubu->Suitcase('Blue');
97
98 However, should Raygun decide to set its own Suitcase() it has now
99 "overridden" Pere::Ubu and is on its own, just like if it had overriden
100 a method:
101
102 # Raygun has an orange suitcase, Pere::Ubu's is still Blue.
103 Raygun->Suitcase('Orange');
104
105 Now that Raygun has overridden Pere::Ubu futher changes by Pere::Ubu no
106 longer effect Raygun.
107
108 # Raygun still has an orange suitcase, but Pere::Ubu is using Samsonite.
109 Pere::Ubu->Suitcase('Samsonite');
110
112 See Class::MakeMethods for general information about this distribution.
113
114 See Class::MakeMethods::Emulator for more about this family of sub‐
115 classes.
116
117 See Class::Data::Inheritable for documentation of the original module.
118
119 See perltootc for a discussion of class data in Perl.
120
121 See Class::MakeMethods::Standard::Inheritable and Class::MakeMeth‐
122 ods::Template::ClassInherit for inheritable data methods.
123
124
125
126perl v5.8.8 2004-09-M0a6keMethods::Emulator::Inheritable(3)