Class::MOP - refactoring the binary tree test code
[gitmo/Class-MOP.git] / lib / Class / MOP.pm
CommitLineData
94b19069 1
2package Class::MOP;
3
4use strict;
5use warnings;
6
8b978dd5 7use Scalar::Util 'blessed';
8
2eb717d5 9use Class::MOP::Class;
10use Class::MOP::Attribute;
11use Class::MOP::Method;
12
94b19069 13our $VERSION = '0.01';
14
2eb717d5 15sub import {
16 shift;
17 return unless @_;
18 if ($_[0] eq ':universal') {
19 *UNIVERSAL::meta = sub {
20 Class::MOP::Class->initialize(blessed($_[0]) || $_[0])
21 };
22 }
23}
8b978dd5 24
94b19069 251;
26
27__END__
28
29=pod
30
31=head1 NAME
32
33Class::MOP - A Meta Object Protocol for Perl 5
34
35=head1 SYNOPSIS
36
2eb717d5 37 use Class::MOP ':universal';
38
39 package Foo;
40
41 Foo->meta->add_method('foo' => sub { ... });
94b19069 42
43=head1 DESCRIPTON
44
45This module is an attempt to create a meta object protocol for the
46Perl 5 object system. It makes no attempt to change the behavior or
47characteristics of the Perl 5 object system, only to create a
27e31eaf 48protocol for its manipulation and introspection.
94b19069 49
50That said, it does attempt to create the tools for building a rich
51set of extensions to the Perl 5 object system. Every attempt has been
52made for these tools to keep to the spirit of the Perl 5 object
53system that we all know and love.
54
bfe4d0fc 55=head2 What is a Meta Object Protocol?
56
57A meta object protocol is an API to an object system.
58
59To be more specific, it is a set of abstractions of the components of
60an object system (typically things like; classes, object, methods,
61object attributes, etc.). These abstractions can then be used to both
62inspect and manipulate the object system which they describe.
63
64It can be said that there are two MOPs for any object system; the
65implicit MOP, and the explicit MOP. The implicit MOP handles things
66like method dispatch or inheritance, which happen automatically as
67part of how the object system works. The explicit MOP typically
68handles the introspection/reflection features of the object system.
69All object systems have implicit MOPs, without one, they would not
70work. Explict MOPs however as less common, and depending on the
71language can vary from restrictive (Reflection in Java or C#) to
72wide open (CLOS is a perfect example).
73
e16da3e6 74=head2 Yet Another Class Builder!! Why?
75
76This is B<not> a class builder so much as it is a I<class builder
77B<builder>>. My intent is that an end user does not use this module
78directly, but instead this module is used by module authors to
79build extensions and features onto the Perl 5 object system.
80
94b19069 81=head2 Who is this module for?
82
83This module is specifically for anyone who has ever created or
84wanted to create a module for the Class:: namespace. The tools which
85this module will provide will hopefully make it easier to do more
86complex things with Perl 5 classes by removing such barriers as
87the need to hack the symbol tables, or understand the fine details
88of method dispatch.
89
bfe4d0fc 90=head2 What changes do I have to make to use this module?
91
2eb717d5 92This module was designed to be as unintrusive as possible. Many of
bfe4d0fc 93it's features are accessible without B<any> change to your existsing
94code at all. It is meant to be a compliment to your existing code and
2eb717d5 95not an intrusion on your code base. Unlike many other B<Class::>
96modules, this module does require you subclass it, or even that you
97C<use> it in within your module's package.
bfe4d0fc 98
2eb717d5 99The only features which requires additions to your code are the
100attribute handling and instance construction features, and these are
101both optional features as well. The only reason for this is because
102Perl 5's object system does not actually have these features built
103in. More information about this feature can be found below.
bfe4d0fc 104
105=head2 A Note about Performance?
106
107It is a common misconception that explict MOPs are performance drains.
108But this is not a universal truth at all, it is an side-effect of
109specific implementations. For instance, using Java reflection is much
110slower because the JVM cannot take advantage of any compiler
111optimizations, and the JVM has to deal with much more runtime type
112information as well. Reflection in C# is marginally better as it was
113designed into the language and runtime (the CLR). In contrast, CLOS
114(the Common Lisp Object System) was built to support an explicit MOP,
115and so performance is tuned for it.
116
117This library in particular does it's absolute best to avoid putting
2eb717d5 118B<any> drain at all upon your code's performance. In fact, by itself
119it does nothing to affect your existing code. So you only pay for
120what you actually use.
bfe4d0fc 121
94b19069 122=head1 PROTOCOLS
123
124The protocol is divided into 3 main sub-protocols:
125
126=over 4
127
128=item The Class protocol
129
130This provides a means of manipulating and introspecting a Perl 5
131class. It handles all of symbol table hacking for you, and provides
132a rich set of methods that go beyond simple package introspection.
133
552e3d24 134See L<Class::MOP::Class> for more details.
135
94b19069 136=item The Attribute protocol
137
138This provides a consistent represenation for an attribute of a
139Perl 5 class. Since there are so many ways to create and handle
140atttributes in Perl 5 OO, this attempts to provide as much of a
141unified approach as possible, while giving the freedom and
142flexibility to subclass for specialization.
143
552e3d24 144See L<Class::MOP::Attribute> for more details.
145
94b19069 146=item The Method protocol
147
148This provides a means of manipulating and introspecting methods in
149the Perl 5 object system. As with attributes, there are many ways to
150approach this topic, so we try to keep it pretty basic, while still
151making it possible to extend the system in many ways.
152
552e3d24 153See L<Class::MOP::Method> for more details.
94b19069 154
155=back
156
552e3d24 157=head1 SEE ALSO
8b978dd5 158
552e3d24 159=head2 Books
8b978dd5 160
161=over 4
162
552e3d24 163=item "The Art of the Meta Object Protocol"
8b978dd5 164
552e3d24 165=item "Advances in Object-Oriented Metalevel Architecture and Reflection"
8b978dd5 166
94b19069 167=back
168
552e3d24 169=head2 Prior Art
8b978dd5 170
171=over 4
172
552e3d24 173=item The Perl 6 MetaModel work
8b978dd5 174
175=over 4
176
552e3d24 177=item L<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel>
8b978dd5 178
552e3d24 179=item L<http://svn.openfoundry.org/pugs/perl5/Perl6-ObjectSpace>
8b978dd5 180
181=back
182
94b19069 183=back
184
185=head1 AUTHOR
186
187Stevan Little E<gt>stevan@iinteractive.comE<lt>
188
552e3d24 189Rob Kinyon E<gt>rob@iinteractive.comE<lt>
190
94b19069 191=head1 COPYRIGHT AND LICENSE
192
193Copyright 2006 by Infinity Interactive, Inc.
194
195L<http://www.iinteractive.com>
196
197This library is free software; you can redistribute it and/or modify
198it under the same terms as Perl itself.
199
200=cut