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