9 use Scalar::Util 'blessed', 'reftype';
11 use Sub::Name 'subname';
13 use Moose::Meta::Class;
14 use Moose::Meta::SafeMixin;
15 use Moose::Meta::Attribute;
18 use Moose::Util::TypeConstraints ':no_export';
20 # bootstrap the mixin module
21 Moose::Meta::SafeMixin::mixin(Moose::Meta::Class->meta, 'Moose::Meta::SafeMixin');
27 Moose::Util::TypeConstraints->import($pkg);
30 if ($pkg->can('meta')) {
32 (blessed($meta) && $meta->isa('Class::MOP::Class'))
33 || confess "Whoops, not møøsey enough";
36 $meta = Moose::Meta::Class->initialize($pkg => (
37 ':attribute_metaclass' => 'Moose::Meta::Attribute'
39 $meta->add_method('meta' => sub {
40 # re-initialize so it inherits properly
41 Moose::Meta::Class->initialize($pkg => (
42 ':attribute_metaclass' => 'Moose::Meta::Attribute'
48 # &alias_method will install the method, but it
49 # will not name it with
52 $meta->alias_method('extends' => subname 'Moose::extends' => sub { $meta->superclasses(@_) });
55 $meta->alias_method('with' => subname 'Moose::with' => sub { $meta->mixin($_[0]) });
58 $meta->alias_method('has' => subname 'Moose::has' => sub {
59 my ($name, %options) = @_;
60 if (exists $options{is}) {
61 if ($options{is} eq 'ro') {
62 $options{reader} = $name;
64 elsif ($options{is} eq 'rw') {
65 $options{accessor} = $name;
68 if (exists $options{isa}) {
69 if (reftype($options{isa}) && reftype($options{isa}) eq 'CODE') {
70 $options{type_constraint} = $options{isa};
73 $options{type_constraint} = Moose::Util::TypeConstraints::subtype(
74 Object => Moose::Util::TypeConstraints::where { $_->isa($options{isa}) }
78 $meta->add_attribute($name, %options)
81 # handle method modifers
82 $meta->alias_method('before' => subname 'Moose::before' => sub {
84 $meta->add_before_method_modifier($_, $code) for @_;
86 $meta->alias_method('after' => subname 'Moose::after' => sub {
88 $meta->add_after_method_modifier($_, $code) for @_;
90 $meta->alias_method('around' => subname 'Moose::around' => sub {
92 $meta->add_around_method_modifier($_, $code) for @_;
95 # make sure they inherit from Moose::Object
96 $meta->superclasses('Moose::Object')
97 unless $meta->superclasses();
99 # we recommend using these things
100 # so export them for them
101 $meta->alias_method('confess' => \&confess);
102 $meta->alias_method('blessed' => \&blessed);
113 Moose - Moose, it's the new Camel
120 has 'x' => (isa => Int(), is => 'rw');
121 has 'y' => (isa => Int(), is => 'rw');
134 has 'z' => (isa => Int());
136 after 'clear' => sub {
143 This is a B<very> early release of this module, it still needs
144 some fine tuning and B<lots> more documentation. I am adopting
145 the I<release early and release often> approach with this module,
146 so keep an eye on your favorite CPAN mirror!
150 Moose is an extension of the Perl 5 object system.
152 =head2 Another object system!?!?
154 Yes, I know there has been an explosion recently of new ways to
155 build object's in Perl 5, most of them based on inside-out objects,
156 and other such things. Moose is different because it is not a new
157 object system for Perl 5, but instead an extension of the existing
160 Moose is built on top of L<Class::MOP>, which is a metaclass system
161 for Perl 5. This means that Moose not only makes building normal
162 Perl 5 objects better, but it also provides the power of metaclass
165 =head2 What does Moose stand for??
167 Moose doesn't stand for one thing in particular, however, if you
168 want, here are a few of my favorites, feel free to contribute
173 =item Makes Other Object Systems Envious
175 =item Makes Object Orientation So Easy
177 =item Makes Object Orientation Sound Easy
179 =item Makes Object Orientation Spiffy- Er
181 =item My Overcraft Overfilled (with) Some Eels
183 =item Moose Often Ovulate Sorta Early
185 =item Most Other Object Systems Emasculate
187 =item Many Overloaded Object Systems Exists
189 =item Moose Offers Often Super Extensions
195 All complex software has bugs lurking in it, and this module is no
196 exception. If you find a bug please either email me, or add the bug
201 Stevan Little E<lt>stevan@iinteractive.comE<gt>
203 =head1 COPYRIGHT AND LICENSE
205 Copyright 2006 by Infinity Interactive, Inc.
207 L<http://www.iinteractive.com>
209 This library is free software; you can redistribute it and/or modify
210 it under the same terms as Perl itself.