MOOOOOOOOOOOOOOOOOOOOOOSSSSEE
[gitmo/Moose.git] / lib / Moose.pm
CommitLineData
fcd84ca9 1
c0e30cf5 2use lib '/Users/stevan/CPAN/Class-MOP/Class-MOP/lib';
3
fcd84ca9 4package Moose;
5
6use strict;
7use warnings;
8
9our $VERSION = '0.01';
10
11use Scalar::Util 'blessed';
12use Carp 'confess';
bc1e29b5 13use Sub::Name 'subname';
fcd84ca9 14
c0e30cf5 15use Moose::Meta::Class;
16use Moose::Meta::Attribute;
17
fcd84ca9 18use Moose::Object;
19
a15dff8d 20require Moose::Util::TypeConstraints;
21
fcd84ca9 22sub import {
23 shift;
24 my $pkg = caller();
25
a15dff8d 26 Moose::Util::TypeConstraints->import($pkg);
27
fcd84ca9 28 my $meta;
29 if ($pkg->can('meta')) {
30 $meta = $pkg->meta();
31 (blessed($meta) && $meta->isa('Class::MOP::Class'))
32 || confess "Whoops, not møøsey enough";
33 }
34 else {
c0e30cf5 35 $meta = Moose::Meta::Class->initialize($pkg => (
36 ':attribute_metaclass' => 'Moose::Meta::Attribute'
bc1e29b5 37 ));
fcd84ca9 38 }
ad1ac1bd 39
bc1e29b5 40 # NOTE:
41 # &alias_method will install the method, but it
42 # will not name it with
43
44 # handle superclasses
45 $meta->alias_method('extends' => subname 'Moose::extends' => sub { $meta->superclasses(@_) });
46
c0e30cf5 47 # handle attributes
bc1e29b5 48 $meta->alias_method('has' => subname 'Moose::has' => sub { $meta->add_attribute(@_) });
3c7278fb 49
c0e30cf5 50 # handle method modifers
bc1e29b5 51 $meta->alias_method('before' => subname 'Moose::before' => sub {
e5ebe4ce 52 my $code = pop @_;
53 $meta->add_before_method_modifier($_, $code) for @_;
54 });
bc1e29b5 55 $meta->alias_method('after' => subname 'Moose::after' => sub {
e5ebe4ce 56 my $code = pop @_;
57 $meta->add_after_method_modifier($_, $code) for @_;
58 });
bc1e29b5 59 $meta->alias_method('around' => subname 'Moose::around' => sub {
c0e30cf5 60 my $code = pop @_;
61 $meta->add_around_method_modifier($_, $code) for @_;
62 });
e5ebe4ce 63
c0e30cf5 64 # make sure they inherit from Moose::Object
fcd84ca9 65 $meta->superclasses('Moose::Object')
66 unless $meta->superclasses();
ad1ac1bd 67
c0e30cf5 68 # we recommend using these things
69 # so export them for them
ad1ac1bd 70 $meta->alias_method('confess' => \&confess);
71 $meta->alias_method('blessed' => \&blessed);
fcd84ca9 72}
73
741;
75
76__END__
77
78=pod
79
80=head1 NAME
81
82Moose -
83
84=head1 SYNOPSIS
09fdc1dc 85
fcd84ca9 86=head1 DESCRIPTION
87
88=head1 OTHER NAMES
89
3c7278fb 90Makes Other Object Systems Envious
91
92Most Other Objects Suck Eggs
93
94Makes Object Orientation So Easy
95
96Metacircular Object Oriented Systems Environment
97
fcd84ca9 98=head1 BUGS
99
100All complex software has bugs lurking in it, and this module is no
101exception. If you find a bug please either email me, or add the bug
102to cpan-RT.
103
104=head1 CODE COVERAGE
105
106I use L<Devel::Cover> to test the code coverage of my tests, below is the
107L<Devel::Cover> report on this module's test suite.
108
109=head1 ACKNOWLEDGEMENTS
110
111=head1 AUTHOR
112
113Stevan Little E<lt>stevan@iinteractive.comE<gt>
114
115=head1 COPYRIGHT AND LICENSE
116
117Copyright 2006 by Infinity Interactive, Inc.
118
119L<http://www.iinteractive.com>
120
121This library is free software; you can redistribute it and/or modify
122it under the same terms as Perl itself.
123
124=cut