0.06
[gitmo/Moose-Autobox.git] / lib / Moose / Autobox.pm
1
2 package Moose::Autobox;
3
4 use strict;
5 use warnings;
6
7 use Carp        qw(confess);
8 use Scalar::Util ();
9
10 our $VERSION = '0.06';
11
12 use base 'autobox';
13
14 use Moose::Autobox::Undef;
15
16 sub import {
17     (shift)->SUPER::import(
18         DEFAULT => 'Moose::Autobox::',
19         UNDEF   => 'Moose::Autobox::Undef',
20     );
21 }
22
23 sub mixin_additional_role {
24     my ($class, $type, $role) = @_;
25     ($type =~ /SCALAR|ARRAY|HASH|CODE/)
26         || confess "Can only add additional roles to SCALAR, ARRAY, HASH or CODE";
27     Moose::Util::apply_all_roles(('Moose::Autobox::' . $type)->meta, ($role));
28 }
29
30 {
31                         
32     package Moose::Autobox::SCALAR;
33
34     use Moose::Autobox::Scalar;
35
36     use metaclass 'Moose::Meta::Class';
37
38     Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Scalar'));
39
40     *does = \&Moose::Object::does;
41
42     package Moose::Autobox::ARRAY;
43
44     use Moose::Autobox::Array;
45
46     use metaclass 'Moose::Meta::Class';
47
48     Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Array'));
49
50     *does = \&Moose::Object::does;
51
52     package Moose::Autobox::HASH;
53
54     use Moose::Autobox::Hash;
55
56     use metaclass 'Moose::Meta::Class';
57
58     Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Hash'));
59
60     *does = \&Moose::Object::does;
61
62     package Moose::Autobox::CODE;
63
64     use Moose::Autobox::Code;
65
66     use metaclass 'Moose::Meta::Class';
67
68     Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Code'));
69
70     *does = \&Moose::Object::does;            
71  
72
73                  
74 1;
75
76 __END__
77
78 =pod
79
80 =head1 NAME 
81
82 Moose::Autobox - Ruby ain't got nothin on us
83
84 =head1 SYNOPOSIS
85
86   use Moose::Autobox;
87   
88   print 'Print squares from 1 to 10 : ';
89   print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
90
91 =head1 CAVEAT
92
93 First, a warning.
94
95 This module is very very very very very very very experimental. It 
96 makes use of a very experimental module (L<autobox>) and uses some 
97 shiney new technology (L<Moose::Role>) to accomplish it's goals.
98
99 Use this at your own risk. If it breaks the lamp in the living room
100 and your mother yells at you, don't come complaining to me.
101
102 Also, as this is so experimental, it's API should not be considered 
103 to be stable. It could very well change in radical ways.
104
105 =head1 DESCRIPTION
106
107 Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH
108 & CODE for use with L<autobox>. It does this using a hierarchy of 
109 roles in a manner similar to what Perl 6 I<might> do. This module, 
110 like L<Class::MOP> and L<Moose>, was inspired by my work on the 
111 Perl 6 Object Space, and the 'core types' implemented there.
112
113 =head2 A quick word about autobox
114
115 The L<autobox> module provides the ability for calling 'methods' 
116 on normal Perl values like Scalars, Arrays, Hashes and Code 
117 references. This gives the illusion that Perl's types are first-class 
118 objects. However, this is only an illusion, albeit a very nice one.
119 I created this module because L<autobox> itself does not actually 
120 provide an implementation for the Perl types but instead only provides 
121 the 'hooks' for others to add implementation too.
122
123 =head2 Is this for real? or just play?
124
125 My intent is to try and make this module as production worthy as 
126 possible. This may or may not be possible, depending on how well 
127 L<autobox> works out. At this point, I have high hopes for things
128 but only time (and more tests and code) will tell.
129
130 =head1 METHODS
131
132 =over 4
133
134 =item B<mixin_additional_role ($type, $role)>
135
136 This will mixin an additonal C<$role> into a certain C<$type>. The 
137 types can be SCALAR, ARRAY, HASH or CODE.
138
139 This can be used to add additional methods to the types, see the 
140 F<examples/units/> directory for some examples.
141
142 =back
143
144 =head1 TODO
145
146 =over 4
147
148 =item More docs
149
150 =item More tests
151
152 =back
153   
154 =head1 BUGS
155
156 All complex software has bugs lurking in it, and this module is no 
157 exception. If you find a bug please either email me, or add the bug
158 to cpan-RT.
159
160 =head1 AUTHOR
161
162 Stevan Little E<lt>stevan@iinteractive.comE<gt>
163
164 B<with contributions from:>
165
166 Anders (Debolaz) Nor Berle
167
168 Matt (mst) Trout
169
170 renormalist
171
172 =head1 COPYRIGHT AND LICENSE
173
174 Copyright 2006-2007 by Infinity Interactive, Inc.
175
176 L<http://www.iinteractive.com>
177
178 This library is free software; you can redistribute it and/or modify
179 it under the same terms as Perl itself.
180
181 =cut