1MakeMethods::Emulator::UIsnehrerCiotnatbrlieb(u3t)ed PerMlakDeoMceutmheondtsa:t:iEomnulator::Inheritable(3)
2
3
4

NAME

6       Class::MakeMethods::Emulator::Inheritable - Emulate Class::Inheritable
7

SYNOPSIS

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

DESCRIPTION

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
24       Class::MakeMethods::Emulator::Inheritable is identical to that of
25       Class::Data::Inheritable.
26
27       Class::Data::Inheritable is for creating accessor/mutators to class
28       data.  That is, if you want to store something about your class as a
29       whole (instead of about a single object).  This data is then inherited
30       by your subclasses and can be overriden.
31

USAGE

33       As specified by Class::Data::Inheritable, clients should inherit from
34       this module and then invoke the mk_classdata() method for each class
35       method desired:
36
37         Class->mk_classdata($data_accessor_name);
38
39       This is a class method used to declare new class data accessors.  A new
40       accessor will be created in the Class using the name from
41       $data_accessor_name.
42
43         Class->mk_classdata($data_accessor_name, $initial_value);
44
45       You may also pass a second argument to initialize the value.
46
47       To facilitate overriding, mk_classdata creates an alias to the
48       accessor, _field_accessor().  So Suitcase() would have an alias
49       _Suitcase_accessor() that does the exact same thing as Suitcase().
50       This is useful if you want to alter the behavior of a single accessor
51       yet still get the benefits of inheritable class data.  For example.
52
53         sub Suitcase {
54             my($self) = shift;
55             warn "Fashion tragedy" if @_ and $_[0] eq 'Plaid';
56
57             $self->_Suitcase_accessor(@_);
58         }
59

COMPATIBILITY

61       Note that the internal implementation of
62       Class::MakeMethods::ClassInherit does not match that of
63       Class::Data::Inheritable. In particular, Class::Data::Inheritable
64       installs new methods in subclasses when they first initialize their
65       value, while
66

EXAMPLE

68       The example provided by Class::Data::Inheritable is equally applicable
69       to this emulator.
70
71         package Pere::Ubu;
72         use base qw(Class::MakeMethods::Emulator::Inheritable);
73         Pere::Ubu->mk_classdata('Suitcase');
74
75       will generate the method Suitcase() in the class Pere::Ubu.
76
77       This new method can be used to get and set a piece of class data.
78
79         Pere::Ubu->Suitcase('Red');
80         $suitcase = Pere::Ubu->Suitcase;
81
82       The interesting part happens when a class inherits from Pere::Ubu:
83
84         package Raygun;
85         use base qw(Pere::Ubu);
86
87         # Raygun's suitcase is Red.
88         $suitcase = Raygun->Suitcase;
89
90       Raygun inherits its Suitcase class data from Pere::Ubu.
91
92       Inheritance of class data works analgous to method inheritance.  As
93       long as Raygun does not "override" its inherited class data (by using
94       Suitcase() to set a new value) it will continue to use whatever is set
95       in Pere::Ubu and inherit further changes:
96
97         # Both Raygun's and Pere::Ubu's suitcases are now Blue
98         Pere::Ubu->Suitcase('Blue');
99
100       However, should Raygun decide to set its own Suitcase() it has now
101       "overridden" Pere::Ubu and is on its own, just like if it had overriden
102       a method:
103
104         # Raygun has an orange suitcase, Pere::Ubu's is still Blue.
105         Raygun->Suitcase('Orange');
106
107       Now that Raygun has overridden Pere::Ubu futher changes by Pere::Ubu no
108       longer effect Raygun.
109
110         # Raygun still has an orange suitcase, but Pere::Ubu is using Samsonite.
111         Pere::Ubu->Suitcase('Samsonite');
112

SEE ALSO

114       See Class::MakeMethods for general information about this distribution.
115
116       See Class::MakeMethods::Emulator for more about this family of
117       subclasses.
118
119       See Class::Data::Inheritable for documentation of the original module.
120
121       See perltootc for a discussion of class data in Perl.
122
123       See Class::MakeMethods::Standard::Inheritable and
124       Class::MakeMethods::Template::ClassInherit for inheritable data
125       methods.
126
127
128
129perl v5.38.0                      2023-07-M2a0keMethods::Emulator::Inheritable(3)
Impressum