2 use lib '/Users/stevan/Projects/CPAN/Class-MOP/Class-MOP/lib';
11 use Scalar::Util 'blessed', 'reftype';
13 use Sub::Name 'subname';
15 use UNIVERSAL::require;
19 use Moose::Meta::Class;
20 use Moose::Meta::Attribute;
23 use Moose::Util::TypeConstraints ':no_export';
29 # we should never export to main
30 return if $pkg eq 'main';
32 Moose::Util::TypeConstraints->import($pkg);
34 # make a subtype for each Moose class
35 Moose::Util::TypeConstraints::subtype($pkg
36 => Moose::Util::TypeConstraints::as Object
37 => Moose::Util::TypeConstraints::where { $_->isa($pkg) }
41 if ($pkg->can('meta')) {
43 (blessed($meta) && $meta->isa('Class::MOP::Class'))
44 || confess "Whoops, not møøsey enough";
47 $meta = Moose::Meta::Class->initialize($pkg => (
48 ':attribute_metaclass' => 'Moose::Meta::Attribute'
50 $meta->add_method('meta' => sub {
51 # re-initialize so it inherits properly
52 Moose::Meta::Class->initialize($pkg => (
53 ':attribute_metaclass' => 'Moose::Meta::Attribute'
59 # &alias_method will install the method, but it
60 # will not name it with
63 $meta->alias_method('extends' => subname 'Moose::extends' => sub {
65 $meta->superclasses(@_)
69 $meta->alias_method('has' => subname 'Moose::has' => sub {
70 my ($name, %options) = @_;
71 if (exists $options{is}) {
72 if ($options{is} eq 'ro') {
73 $options{reader} = $name;
75 elsif ($options{is} eq 'rw') {
76 $options{accessor} = $name;
79 if (exists $options{isa}) {
80 # allow for anon-subtypes here ...
81 if (reftype($options{isa}) && reftype($options{isa}) eq 'CODE') {
82 $options{type_constraint} = $options{isa};
85 # otherwise assume it is a constraint
86 my $constraint = Moose::Util::TypeConstraints::find_type_constraint($options{isa});
87 # if the constraing it not found ....
88 unless (defined $constraint) {
89 # assume it is a foreign class, and make
90 # an anon constraint for it
91 $constraint = Moose::Util::TypeConstraints::subtype(
92 Object => Moose::Util::TypeConstraints::where { $_->isa($constraint) }
95 $options{type_constraint} = $constraint;
98 $meta->add_attribute($name, %options)
101 # handle method modifers
102 $meta->alias_method('before' => subname 'Moose::before' => sub {
104 $meta->add_before_method_modifier($_, $code) for @_;
106 $meta->alias_method('after' => subname 'Moose::after' => sub {
108 $meta->add_after_method_modifier($_, $code) for @_;
110 $meta->alias_method('around' => subname 'Moose::around' => sub {
112 $meta->add_around_method_modifier($_, $code) for @_;
115 # make sure they inherit from Moose::Object
116 $meta->superclasses('Moose::Object')
117 unless $meta->superclasses();
119 # we recommend using these things
120 # so export them for them
121 $meta->alias_method('confess' => \&Carp::confess);
122 $meta->alias_method('blessed' => \&Scalar::Util::blessed);
133 Moose - Moose, it's the new Camel
140 has 'x' => (isa => 'Int', is => 'rw');
141 has 'y' => (isa => 'Int', is => 'rw');
154 has 'z' => (isa => 'Int');
156 after 'clear' => sub {
163 This is a B<very> early release of this module, it still needs
164 some fine tuning and B<lots> more documentation. I am adopting
165 the I<release early and release often> approach with this module,
166 so keep an eye on your favorite CPAN mirror!
170 Moose is an extension of the Perl 5 object system.
172 =head2 Another object system!?!?
174 Yes, I know there has been an explosion recently of new ways to
175 build object's in Perl 5, most of them based on inside-out objects,
176 and other such things. Moose is different because it is not a new
177 object system for Perl 5, but instead an extension of the existing
180 Moose is built on top of L<Class::MOP>, which is a metaclass system
181 for Perl 5. This means that Moose not only makes building normal
182 Perl 5 objects better, but it also provides the power of metaclass
185 =head2 What does Moose stand for??
187 Moose doesn't stand for one thing in particular, however, if you
188 want, here are a few of my favorites, feel free to contribute
193 =item Make Other Object Systems Envious
195 =item Makes Object Orientation So Easy
197 =item Makes Object Orientation Spiffy- Er (sorry ingy)
199 =item Most Other Object Systems Emasculate
201 =item My Overcraft Overfilled (with) Some Eels
203 =item Moose Often Ovulate Sorta Early
205 =item Many Overloaded Object Systems Exists
207 =item Moose Offers Often Super Extensions
211 =head1 ACKNOWLEDGEMENTS
215 =item I blame Sam Vilain for giving me my first hit of meta-model crack.
217 =item I blame Audrey Tang for encouraging that meta-crack habit in #perl6.
219 =item Without the love and encouragement of Yuval "nothingmuch" Kogman,
220 this module would not be possible (and it wouldn't have a name).
222 =item The basis of the TypeContraints module was Rob Kinyon's idea
223 originally, I just ran with it.
231 =item L<http://forum2.org/moose/>
237 All complex software has bugs lurking in it, and this module is no
238 exception. If you find a bug please either email me, or add the bug
243 Stevan Little E<lt>stevan@iinteractive.comE<gt>
245 =head1 COPYRIGHT AND LICENSE
247 Copyright 2006 by Infinity Interactive, Inc.
249 L<http://www.iinteractive.com>
251 This library is free software; you can redistribute it and/or modify
252 it under the same terms as Perl itself.