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 # we should never export to main
28 return if $pkg eq 'main';
30 Moose::Util::TypeConstraints->import($pkg);
33 if ($pkg->can('meta')) {
35 (blessed($meta) && $meta->isa('Class::MOP::Class'))
36 || confess "Whoops, not møøsey enough";
39 $meta = Moose::Meta::Class->initialize($pkg => (
40 ':attribute_metaclass' => 'Moose::Meta::Attribute'
42 $meta->add_method('meta' => sub {
43 # re-initialize so it inherits properly
44 Moose::Meta::Class->initialize($pkg => (
45 ':attribute_metaclass' => 'Moose::Meta::Attribute'
51 # &alias_method will install the method, but it
52 # will not name it with
55 $meta->alias_method('extends' => subname 'Moose::extends' => sub { $meta->superclasses(@_) });
58 $meta->alias_method('with' => subname 'Moose::with' => sub { $meta->mixin($_[0]) });
61 $meta->alias_method('has' => subname 'Moose::has' => sub {
62 my ($name, %options) = @_;
63 if (exists $options{is}) {
64 if ($options{is} eq 'ro') {
65 $options{reader} = $name;
67 elsif ($options{is} eq 'rw') {
68 $options{accessor} = $name;
71 if (exists $options{isa}) {
72 if (reftype($options{isa}) && reftype($options{isa}) eq 'CODE') {
73 $options{type_constraint} = $options{isa};
76 $options{type_constraint} = Moose::Util::TypeConstraints::subtype(
77 Object => Moose::Util::TypeConstraints::where { $_->isa($options{isa}) }
81 $meta->add_attribute($name, %options)
84 # handle method modifers
85 $meta->alias_method('before' => subname 'Moose::before' => sub {
87 $meta->add_before_method_modifier($_, $code) for @_;
89 $meta->alias_method('after' => subname 'Moose::after' => sub {
91 $meta->add_after_method_modifier($_, $code) for @_;
93 $meta->alias_method('around' => subname 'Moose::around' => sub {
95 $meta->add_around_method_modifier($_, $code) for @_;
99 $meta->alias_method('next_method' => subname 'Moose::next_method' => sub {
100 my $method_name = (split '::' => (caller(1))[3])[-1];
101 my $next_method = $meta->find_next_method_by_name($method_name);
102 (defined $next_method)
103 || confess "Could not find next-method for '$method_name'";
107 # make sure they inherit from Moose::Object
108 $meta->superclasses('Moose::Object')
109 unless $meta->superclasses();
111 # we recommend using these things
112 # so export them for them
113 $meta->alias_method('confess' => \&confess);
114 $meta->alias_method('blessed' => \&blessed);
125 Moose - Moose, it's the new Camel
132 has 'x' => (isa => Int(), is => 'rw');
133 has 'y' => (isa => Int(), is => 'rw');
146 has 'z' => (isa => Int());
148 after 'clear' => sub {
155 This is a B<very> early release of this module, it still needs
156 some fine tuning and B<lots> more documentation. I am adopting
157 the I<release early and release often> approach with this module,
158 so keep an eye on your favorite CPAN mirror!
162 Moose is an extension of the Perl 5 object system.
164 =head2 Another object system!?!?
166 Yes, I know there has been an explosion recently of new ways to
167 build object's in Perl 5, most of them based on inside-out objects,
168 and other such things. Moose is different because it is not a new
169 object system for Perl 5, but instead an extension of the existing
172 Moose is built on top of L<Class::MOP>, which is a metaclass system
173 for Perl 5. This means that Moose not only makes building normal
174 Perl 5 objects better, but it also provides the power of metaclass
177 =head2 What does Moose stand for??
179 Moose doesn't stand for one thing in particular, however, if you
180 want, here are a few of my favorites, feel free to contribute
185 =item Makes Other Object Systems Envious
187 =item Makes Object Orientation So Easy
189 =item Makes Object Orientation Sound Easy
191 =item Makes Object Orientation Spiffy- Er
193 =item My Overcraft Overfilled (with) Some Eels
195 =item Moose Often Ovulate Sorta Early
197 =item Most Other Object Systems Emasculate
199 =item Many Overloaded Object Systems Exists
201 =item Moose Offers Often Super Extensions
207 All complex software has bugs lurking in it, and this module is no
208 exception. If you find a bug please either email me, or add the bug
213 Stevan Little E<lt>stevan@iinteractive.comE<gt>
215 =head1 COPYRIGHT AND LICENSE
217 Copyright 2006 by Infinity Interactive, Inc.
219 L<http://www.iinteractive.com>
221 This library is free software; you can redistribute it and/or modify
222 it under the same terms as Perl itself.