2 use lib '/Users/stevan/CPAN/Class-MOP/Class-MOP/lib';
11 use Scalar::Util 'blessed', 'reftype';
13 use Sub::Name 'subname';
15 use Moose::Meta::Class;
16 use Moose::Meta::Attribute;
19 use Moose::Util::TypeConstraints ':no_export';
25 Moose::Util::TypeConstraints->import($pkg);
28 if ($pkg->can('meta')) {
30 (blessed($meta) && $meta->isa('Class::MOP::Class'))
31 || confess "Whoops, not møøsey enough";
34 $meta = Moose::Meta::Class->initialize($pkg => (
35 ':attribute_metaclass' => 'Moose::Meta::Attribute'
40 # &alias_method will install the method, but it
41 # will not name it with
44 $meta->alias_method('extends' => subname 'Moose::extends' => sub { $meta->superclasses(@_) });
47 $meta->alias_method('has' => subname 'Moose::has' => sub {
48 my ($name, %options) = @_;
49 if (exists $options{is}) {
50 if ($options{is} eq 'ro') {
51 $options{reader} = $name;
53 elsif ($options{is} eq 'rw') {
54 $options{accessor} = $name;
57 if (exists $options{isa}) {
58 if (reftype($options{isa}) && reftype($options{isa}) eq 'CODE') {
59 $options{type_constraint} = $options{isa};
62 $options{type_constraint} = Moose::Util::TypeConstraints::subtype(
63 Object => Moose::Util::TypeConstraints::where { $_->isa($options{isa}) }
67 $meta->add_attribute($name, %options)
70 # handle method modifers
71 $meta->alias_method('before' => subname 'Moose::before' => sub {
73 $meta->add_before_method_modifier($_, $code) for @_;
75 $meta->alias_method('after' => subname 'Moose::after' => sub {
77 $meta->add_after_method_modifier($_, $code) for @_;
79 $meta->alias_method('around' => subname 'Moose::around' => sub {
81 $meta->add_around_method_modifier($_, $code) for @_;
84 # make sure they inherit from Moose::Object
85 $meta->superclasses('Moose::Object')
86 unless $meta->superclasses();
88 # we recommend using these things
89 # so export them for them
90 $meta->alias_method('confess' => \&confess);
91 $meta->alias_method('blessed' => \&blessed);
110 Makes Other Object Systems Envious
112 Makes Object Orientation So Easy
116 All complex software has bugs lurking in it, and this module is no
117 exception. If you find a bug please either email me, or add the bug
122 I use L<Devel::Cover> to test the code coverage of my tests, below is the
123 L<Devel::Cover> report on this module's test suite.
125 =head1 ACKNOWLEDGEMENTS
129 Stevan Little E<lt>stevan@iinteractive.comE<gt>
131 =head1 COPYRIGHT AND LICENSE
133 Copyright 2006 by Infinity Interactive, Inc.
135 L<http://www.iinteractive.com>
137 This library is free software; you can redistribute it and/or modify
138 it under the same terms as Perl itself.