2 use lib '/Users/stevan/Projects/CPAN/Class-MOP/Class-MOP/lib';
11 use Scalar::Util 'blessed', 'reftype';
13 use Sub::Name 'subname';
17 use Moose::Meta::Class;
18 use Moose::Meta::SafeMixin;
19 use Moose::Meta::Attribute;
22 use Moose::Util::TypeConstraints ':no_export';
24 # bootstrap the mixin module
25 Moose::Meta::SafeMixin::mixin(Moose::Meta::Class->meta, 'Moose::Meta::SafeMixin');
31 # we should never export to main
32 return if $pkg eq 'main';
34 Moose::Util::TypeConstraints->import($pkg);
37 if ($pkg->can('meta')) {
39 (blessed($meta) && $meta->isa('Class::MOP::Class'))
40 || confess "Whoops, not møøsey enough";
43 $meta = Moose::Meta::Class->initialize($pkg => (
44 ':attribute_metaclass' => 'Moose::Meta::Attribute'
46 $meta->add_method('meta' => sub {
47 # re-initialize so it inherits properly
48 Moose::Meta::Class->initialize($pkg => (
49 ':attribute_metaclass' => 'Moose::Meta::Attribute'
55 # &alias_method will install the method, but it
56 # will not name it with
59 $meta->alias_method('extends' => subname 'Moose::extends' => sub { $meta->superclasses(@_) });
62 $meta->alias_method('with' => subname 'Moose::with' => sub { $meta->mixin($_[0]) });
65 $meta->alias_method('has' => subname 'Moose::has' => sub {
66 my ($name, %options) = @_;
67 if (exists $options{is}) {
68 if ($options{is} eq 'ro') {
69 $options{reader} = $name;
71 elsif ($options{is} eq 'rw') {
72 $options{accessor} = $name;
75 if (exists $options{isa}) {
76 if (reftype($options{isa}) && reftype($options{isa}) eq 'CODE') {
77 $options{type_constraint} = $options{isa};
80 $options{type_constraint} = Moose::Util::TypeConstraints::subtype(
81 Object => Moose::Util::TypeConstraints::where { $_->isa($options{isa}) }
85 $meta->add_attribute($name, %options)
88 # handle method modifers
89 $meta->alias_method('before' => subname 'Moose::before' => sub {
91 $meta->add_before_method_modifier($_, $code) for @_;
93 $meta->alias_method('after' => subname 'Moose::after' => sub {
95 $meta->add_after_method_modifier($_, $code) for @_;
97 $meta->alias_method('around' => subname 'Moose::around' => sub {
99 $meta->add_around_method_modifier($_, $code) for @_;
102 # make sure they inherit from Moose::Object
103 $meta->superclasses('Moose::Object')
104 unless $meta->superclasses();
106 # we recommend using these things
107 # so export them for them
108 $meta->alias_method('confess' => \&Carp::confess);
109 $meta->alias_method('blessed' => \&Scalar::Util::blessed);
120 Moose - Moose, it's the new Camel
127 has 'x' => (isa => Int(), is => 'rw');
128 has 'y' => (isa => Int(), is => 'rw');
141 has 'z' => (isa => Int());
143 after 'clear' => sub {
150 This is a B<very> early release of this module, it still needs
151 some fine tuning and B<lots> more documentation. I am adopting
152 the I<release early and release often> approach with this module,
153 so keep an eye on your favorite CPAN mirror!
157 Moose is an extension of the Perl 5 object system.
159 =head2 Another object system!?!?
161 Yes, I know there has been an explosion recently of new ways to
162 build object's in Perl 5, most of them based on inside-out objects,
163 and other such things. Moose is different because it is not a new
164 object system for Perl 5, but instead an extension of the existing
167 Moose is built on top of L<Class::MOP>, which is a metaclass system
168 for Perl 5. This means that Moose not only makes building normal
169 Perl 5 objects better, but it also provides the power of metaclass
172 =head2 What does Moose stand for??
174 Moose doesn't stand for one thing in particular, however, if you
175 want, here are a few of my favorites, feel free to contribute
180 =item Make Other Object Systems Envious
182 =item Makes Object Orientation So Easy
184 =item Makes Object Orientation Spiffy- Er (sorry ingy)
186 =item Most Other Object Systems Emasculate
188 =item My Overcraft Overfilled (with) Some Eels
190 =item Moose Often Ovulate Sorta Early
192 =item Many Overloaded Object Systems Exists
194 =item Moose Offers Often Super Extensions
198 =head1 ACKNOWLEDGEMENTS
202 =item I blame Sam Vilain for giving me my first hit of meta-model crack.
204 =item I blame Audrey Tang for encouraging that meta-crack habit in #perl6.
206 =item Without the love and encouragement of Yuval "nothingmuch" Kogman,
207 this module would not be possible (and it wouldn't have a name).
209 =item The basis of the TypeContraints module was Rob Kinyon's idea
210 originally, I just ran with it.
216 All complex software has bugs lurking in it, and this module is no
217 exception. If you find a bug please either email me, or add the bug
222 Stevan Little E<lt>stevan@iinteractive.comE<gt>
224 =head1 COPYRIGHT AND LICENSE
226 Copyright 2006 by Infinity Interactive, Inc.
228 L<http://www.iinteractive.com>
230 This library is free software; you can redistribute it and/or modify
231 it under the same terms as Perl itself.