9 use Scalar::Util 'blessed', 'reftype';
11 use Sub::Name 'subname';
13 use UNIVERSAL::require;
17 use Moose::Meta::Class;
18 use Moose::Meta::Attribute;
19 use Moose::Meta::TypeConstraint;
22 use Moose::Util::TypeConstraints;
28 # we should never export to main
29 return if $pkg eq 'main';
31 Moose::Util::TypeConstraints->import($pkg);
33 # make a subtype for each Moose class
36 => where { $_->isa($pkg) };
39 if ($pkg->can('meta')) {
41 (blessed($meta) && $meta->isa('Class::MOP::Class'))
42 || confess "Whoops, not møøsey enough";
45 $meta = Moose::Meta::Class->initialize($pkg => (
46 ':attribute_metaclass' => 'Moose::Meta::Attribute'
48 $meta->add_method('meta' => sub {
49 # re-initialize so it inherits properly
50 Moose::Meta::Class->initialize($pkg => (
51 ':attribute_metaclass' => 'Moose::Meta::Attribute'
57 # &alias_method will install the method, but it
58 # will not name it with
61 $meta->alias_method('extends' => subname 'Moose::extends' => sub {
63 $meta->superclasses(@_)
67 $meta->alias_method('has' => subname 'Moose::has' => sub {
68 my ($name, %options) = @_;
69 if (exists $options{is}) {
70 if ($options{is} eq 'ro') {
71 $options{reader} = $name;
73 elsif ($options{is} eq 'rw') {
74 $options{accessor} = $name;
77 if (exists $options{isa}) {
78 # allow for anon-subtypes here ...
79 if (blessed($options{isa}) && $options{isa}->isa('Moose::Meta::TypeConstraint')) {
80 $options{type_constraint} = $options{isa};
83 # otherwise assume it is a constraint
84 my $constraint = Moose::Util::TypeConstraints::find_type_constraint($options{isa});
85 # if the constraing it not found ....
86 unless (defined $constraint) {
87 # assume it is a foreign class, and make
88 # an anon constraint for it
89 $constraint = subtype Object => where { $_->isa($options{isa}) };
91 $options{type_constraint} = $constraint;
94 $meta->add_attribute($name, %options)
97 # handle method modifers
98 $meta->alias_method('before' => subname 'Moose::before' => sub {
100 $meta->add_before_method_modifier($_, $code) for @_;
102 $meta->alias_method('after' => subname 'Moose::after' => sub {
104 $meta->add_after_method_modifier($_, $code) for @_;
106 $meta->alias_method('around' => subname 'Moose::around' => sub {
108 $meta->add_around_method_modifier($_, $code) for @_;
111 # make sure they inherit from Moose::Object
112 $meta->superclasses('Moose::Object')
113 unless $meta->superclasses();
115 # we recommend using these things
116 # so export them for them
117 $meta->alias_method('confess' => \&Carp::confess);
118 $meta->alias_method('blessed' => \&Scalar::Util::blessed);
129 Moose - Moose, it's the new Camel
136 has 'x' => (isa => 'Int', is => 'rw');
137 has 'y' => (isa => 'Int', is => 'rw');
150 has 'z' => (isa => 'Int');
152 after 'clear' => sub {
159 This is a B<very> early release of this module, it still needs
160 some fine tuning and B<lots> more documentation. I am adopting
161 the I<release early and release often> approach with this module,
162 so keep an eye on your favorite CPAN mirror!
166 Moose is an extension of the Perl 5 object system.
168 =head2 Another object system!?!?
170 Yes, I know there has been an explosion recently of new ways to
171 build object's in Perl 5, most of them based on inside-out objects,
172 and other such things. Moose is different because it is not a new
173 object system for Perl 5, but instead an extension of the existing
176 Moose is built on top of L<Class::MOP>, which is a metaclass system
177 for Perl 5. This means that Moose not only makes building normal
178 Perl 5 objects better, but it also provides the power of metaclass
181 =head2 What does Moose stand for??
183 Moose doesn't stand for one thing in particular, however, if you
184 want, here are a few of my favorites, feel free to contribute
189 =item Make Other Object Systems Envious
191 =item Makes Object Orientation So Easy
193 =item Makes Object Orientation Spiffy- Er (sorry ingy)
195 =item Most Other Object Systems Emasculate
197 =item My Overcraft Overfilled (with) Some Eels
199 =item Moose Often Ovulate Sorta Early
201 =item Many Overloaded Object Systems Exists
203 =item Moose Offers Often Super Extensions
207 =head1 ACKNOWLEDGEMENTS
211 =item I blame Sam Vilain for giving me my first hit of meta-model crack.
213 =item I blame Audrey Tang for encouraging that meta-crack habit in #perl6.
215 =item Without the love and encouragement of Yuval "nothingmuch" Kogman,
216 this module would not be possible (and it wouldn't have a name).
218 =item The basis of the TypeContraints module was Rob Kinyon's idea
219 originally, I just ran with it.
221 =item Much love to mst & chansen and the whole #moose poose for all the
222 ideas/feature-requests/encouragement
230 =item L<http://forum2.org/moose/>
236 All complex software has bugs lurking in it, and this module is no
237 exception. If you find a bug please either email me, or add the bug
242 Stevan Little E<lt>stevan@iinteractive.comE<gt>
244 =head1 COPYRIGHT AND LICENSE
246 Copyright 2006 by Infinity Interactive, Inc.
248 L<http://www.iinteractive.com>
250 This library is free software; you can redistribute it and/or modify
251 it under the same terms as Perl itself.