Spelling errors
[gitmo/Class-MOP.git] / lib / Class / MOP.pm
CommitLineData
94b19069 1
2package Class::MOP;
3
4use strict;
5use warnings;
6
7our $VERSION = '0.01';
8
91;
10
11__END__
12
13=pod
14
15=head1 NAME
16
17Class::MOP - A Meta Object Protocol for Perl 5
18
19=head1 SYNOPSIS
20
21 # ... coming soon
22
23=head1 DESCRIPTON
24
25This module is an attempt to create a meta object protocol for the
26Perl 5 object system. It makes no attempt to change the behavior or
27characteristics of the Perl 5 object system, only to create a
27e31eaf 28protocol for its manipulation and introspection.
94b19069 29
30That said, it does attempt to create the tools for building a rich
31set of extensions to the Perl 5 object system. Every attempt has been
32made for these tools to keep to the spirit of the Perl 5 object
33system that we all know and love.
34
35=head2 Who is this module for?
36
37This module is specifically for anyone who has ever created or
38wanted to create a module for the Class:: namespace. The tools which
39this module will provide will hopefully make it easier to do more
40complex things with Perl 5 classes by removing such barriers as
41the need to hack the symbol tables, or understand the fine details
42of method dispatch.
43
44=head1 PROTOCOLS
45
46The protocol is divided into 3 main sub-protocols:
47
48=over 4
49
50=item The Class protocol
51
52This provides a means of manipulating and introspecting a Perl 5
53class. It handles all of symbol table hacking for you, and provides
54a rich set of methods that go beyond simple package introspection.
55
56=item The Attribute protocol
57
58This provides a consistent represenation for an attribute of a
59Perl 5 class. Since there are so many ways to create and handle
60atttributes in Perl 5 OO, this attempts to provide as much of a
61unified approach as possible, while giving the freedom and
62flexibility to subclass for specialization.
63
64=item The Method protocol
65
66This provides a means of manipulating and introspecting methods in
67the Perl 5 object system. As with attributes, there are many ways to
68approach this topic, so we try to keep it pretty basic, while still
69making it possible to extend the system in many ways.
70
71=back
72
73What follows is a more detailed documentation on each specific sub
74protocol.
75
76=head2 The Class protocol
77
138f87a7 78=head3 Class construction
94b19069 79
80These methods handle creating Class objects, which can be used to
81both create new classes, and analyze pre-existing ones.
82
83Class::MOP will internally store weakened references to all the
84instances you create with these methods, so that they do not need
85to be created any more than nessecary.
86
87=over 4
88
89=item B<create ($package_name, ?@superclasses, ?%methods, ?%attributes)>
90
91This returns the basic Class object, bringing the specified
92C<$package_name> into existence and adding any of the
93C<@superclasses>, C<%methods> and C<%attributes> to it.
94
95=item B<load ($package_name)>
96
97This returns the basic Class object, after examining the given
98C<$package_name> and attempting to discover it's components (the
99methods, attributes and superclasses).
100
101B<NOTE>: This method makes every attempt to ignore subroutines
102which have been exported by other packages into this one.
103
104=item B<initialize ($package_name, @superclasses, %methods, %attributes)>
105
6d681766 106This creates the actual Class object given a C<$package_name>,
94b19069 107an array of C<@superclasses>, a hash of C<%methods> and a hash
108of C<%attributes>. This method is used by both C<load> and
109C<create>.
110
138f87a7 111=back
112
113=head3 Instance construction
114
115=over 4
116
117=item <create_instance ($canidate, %params)>
118
119This will construct and instance using the C<$canidate> as storage
27e31eaf 120(currently only HASH references are supported). This will collect all
138f87a7 121the applicable attribute meta-objects and layout out the fields in the
122C<$canidate>, it will then initialize them using either use the
123corresponding key in C<%params> or any default value or initializer
124found in the attribute meta-object.
94b19069 125
126=back
127
128=head3 Informational
129
130=over 4
131
132=item C<name>
133
134This is a read-only attribute which returns the package name that
135the Class is stored in.
136
137=item C<version>
138
139This is a read-only attribute which returns the C<$VERSION> of the
140package the Class is stored in.
141
142=back
143
144=head3 Inheritance Relationships
145
146=over 4
147
148=item C<superclasses (?@superclasses)>
149
150This is a read-write attribute which represents the superclass
151relationships of this Class. Basically, it can get and set the
152C<@ISA> for you.
153
154=item C<class_precendence_list>
155
156This computes the a list of the Class's ancestors in the same order
157in which method dispatch will be done.
158
159=back
160
161=head3 Methods
162
163=over 4
164
165=item C<add_method ($method_name, $method)>
166
167This will take a C<$method_name> and CODE reference to that
168C<$method> and install it into the Class.
169
170B<NOTE> : This does absolutely nothing special to C<$method>
171other than use B<Sub::Name> to make sure it is tagged with the
172correct name, and therefore show up correctly in stack traces and
173such.
174
175=item C<has_method ($method_name)>
176
177This just provides a simple way to check if the Class implements
178a specific C<$method_name>. It will I<not> however, attempt to check
179if the class inherits the method.
180
181=item C<get_method ($method_name)>
182
183This will return a CODE reference of the specified C<$method_name>,
184or return undef if that method does not exist.
185
186=item C<remove_method ($method_name)>
187
188This will attempt to remove a given C<$method_name> from the Class.
189It will return the CODE reference that it has removed, and will
190attempt to use B<Sub::Name> to clear the methods associated name.
191
192=item C<get_method_list>
193
194This will return a list of method names for all I<locally> defined
195methods. It does B<not> provide a list of all applicable methods,
196including any inherited ones. If you want a list of all applicable
197methods, use the C<compute_all_applicable_methods> method.
198
199=item C<compute_all_applicable_methods>
200
201This will return a list of all the methods names this Class will
202support, taking into account inheritance. The list will be a list of
203HASH references, each one containing the following information; method
ca843097 204name, the name of the class in which the method lives and a CODE
205reference for the actual method.
94b19069 206
6d681766 207=item C<find_all_methods_by_name ($method_name)>
94b19069 208
209This will traverse the inheritence hierarchy and locate all methods
ca843097 210with a given C<$method_name>. Similar to
211C<compute_all_applicable_methods> it returns a list of HASH references
212with the following information; method name (which will always be the
213same as C<$method_name>), the name of the class in which the method
214lives and a CODE reference for the actual method.
94b19069 215
216=back
217
218=head2 Attributes
219
ca843097 220It should be noted that since there is no one consistent way to define
221the attributes of a class in Perl 5. These methods can only work with
222the information given, and can not easily discover information on
223their own.
94b19069 224
225=over 4
226
138f87a7 227=item C<add_attribute ($attribute_name, $attribute_meta_object)>
228
ca843097 229This stores a C<$attribute_meta_object> in the Class object and
230associates it with the C<$attribute_name>. Unlike methods, attributes
231within the MOP are stored as meta-information only. They will be used
232later to construct instances from (see C<create_instance> above). More
233details about the attribute meta-objects can be found in the L<The
234Attribute protocol> section of this document.
138f87a7 235
236=item C<has_attribute ($attribute_name)>
237
ca843097 238Checks to see if this Class has an attribute by the name of
239C<$attribute_name> and returns a boolean.
138f87a7 240
241=item C<get_attribute ($attribute_name)>
242
ca843097 243Returns the attribute meta-object associated with C<$attribute_name>,
244if none is found, it will return undef.
138f87a7 245
246=item C<remove_attribute ($attribute_name)>
247
ca843097 248This will remove the attribute meta-object stored at
249C<$attribute_name>, then return the removed attribute meta-object.
94b19069 250
ca843097 251B<NOTE:> Removing an attribute will only affect future instances of
252the class, it will not make any attempt to remove the attribute from
253any existing instances of the class.
94b19069 254
138f87a7 255=item C<get_attribute_list>
94b19069 256
ca843097 257This returns a list of attribute names which are defined in the local
258class. If you want a list of all applicable attributes for a class,
259use the C<compute_all_applicable_attributes> method.
94b19069 260
138f87a7 261=item C<compute_all_applicable_attributes>
94b19069 262
ca843097 263This will traverse the inheritance heirachy and return a list of HASH
264references for all the applicable attributes for this class. The HASH
265references will contain the following information; the attribute name,
266the class which the attribute is associated with and the actual
267attribute meta-object
94b19069 268
269=back
270
271=head1 SEE ALSO
272
273=over 4
274
275=item "The Art of the Meta Object Protocol"
276
138f87a7 277=item "Advances in Object-Oriented Metalevel Architecture and Reflection"
94b19069 278
279=back
280
281=head1 AUTHOR
282
283Stevan Little E<gt>stevan@iinteractive.comE<lt>
284
285=head1 COPYRIGHT AND LICENSE
286
287Copyright 2006 by Infinity Interactive, Inc.
288
289L<http://www.iinteractive.com>
290
291This library is free software; you can redistribute it and/or modify
292it under the same terms as Perl itself.
293
294=cut