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