775f6a4f56b5036cd22badc14408ed1360cbe03b
[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.03';
11
12 use base 'autobox';
13
14 sub import {
15     (shift)->SUPER::import(
16         DEFAULT => 'Moose::Autobox::',
17         UNDEF   => 'Moose::Autobox::Undef',
18     );
19 }
20                         
21 package Moose::Autobox::SCALAR;
22 # NOTE:
23 # this doesnt make sense, but 
24 # I need to prevent Moose from 
25 # assiging to @ISA
26 use base 'UNIVERSAL';
27 use Moose;
28 with 'Moose::Autobox::Scalar';
29
30 *does = \&Moose::Object::does;
31
32 package Moose::Autobox::ARRAY;
33 use base 'UNIVERSAL';
34 use Moose;
35 with 'Moose::Autobox::Array';
36
37 *does = \&Moose::Object::does;
38
39 package Moose::Autobox::HASH;
40 use base 'UNIVERSAL';
41 use Moose;
42 with 'Moose::Autobox::Hash';
43
44 *does = \&Moose::Object::does;
45
46 package Moose::Autobox::CODE;
47 use base 'UNIVERSAL';
48 use Moose;
49 with 'Moose::Autobox::Code';  
50
51 *does = \&Moose::Object::does;            
52                  
53 1;
54
55 __END__
56
57 =pod
58
59 =head1 NAME 
60
61 Moose::Autobox - Autoboxed for her pleasure
62
63 =head1 SYNOPOSIS
64
65   use Moose::Autobox;
66   use autobox;
67   
68   print 'Print squares from 1 to 10 : ';
69   print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
70
71 =head1 CAVEAT
72
73 First, a warning.
74
75 This module is very very very very very very very experimental. It 
76 makes use of a very experimental module (L<autobox>) and uses some 
77 shiney new technology (L<Moose::Role>) to accomplish it's goals.
78
79 Use this at your own risk. If it breaks the lamp in the living room
80 and your mother yells at you, don't come complaining to me.
81
82 Also, as this is so experimental, it's API should not be considered 
83 to be stable. It could very well change in radical ways.
84
85 =head1 DESCRIPTION
86
87 Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH
88 & CODE for use with L<autobox>. It does this using a hierarchy of 
89 roles in a manner similar to what Perl 6 I<might> do. This module, 
90 like L<Class::MOP> and L<Moose>, was inspired by my work on the 
91 Perl 6 Object Space, and the 'core types' implemented there.
92
93 =head2 A quick word about autobox
94
95 The L<autobox> module provides the ability for calling 'methods' 
96 on normal Perl values like Scalars, Arrays, Hashes and Code 
97 references. This gives the illusion that Perl's types are first-class 
98 objects. However, this is only an illusion, albeit a very nice one.
99 I created this module because L<autobox> itself does not actually 
100 provide an implementation for the Perl types but instead only provides 
101 the 'hooks' for others to add implementation too.
102
103 =head2 Is this for real? or just play?
104
105 My intent is to try and make this module as production worthy as 
106 possible. This may or may not be possible, depending on how well 
107 L<autobox> works out. At this point, I have high hopes for things
108 but only time (and more tests and code) will tell.
109
110 =head1 ROLES
111
112 This is a rough diagram of the roles involved to get our 4 
113 autoboxed types (SCALAR, ARRAY, HASH & CODE). 
114                                                           
115   +------------------------+-------------------------------+
116   |  Identity              |  Behavioral                   |
117   +------------------------+-------------------------------+
118   |  Item                  |                               |
119   |      Undef             |                               |
120   |      Defined           |                               |
121   |          Scalar*     <-|- String, Number <--+          |
122   |          Ref           |                    |-- Value  |
123   |              Array*  <-|- List <------------+          |
124   |              Hash*     |                               |
125   |              Code*     |                               |
126   |                        |                               |
127   +------------------------+-------------------------------+
128                                                           
129   * indicates actual autoboxed types
130
131 =head1 TODO
132
133 =over 4
134
135 =item More docs
136
137 =item More tests
138
139 =back
140   
141 =head1 NOTES  
142   
143   - String, Number & List are currently the only 'Value's.
144   
145   - Indexed is pretty much an interface, we probably will 
146     need more of these (see Smalltalk Collection Trait 
147     Refactoring)
148   
149 =head1 BUGS
150
151 All complex software has bugs lurking in it, and this module is no 
152 exception. If you find a bug please either email me, or add the bug
153 to cpan-RT.
154
155 =head1 AUTHOR
156
157 Stevan Little E<lt>stevan@iinteractive.comE<gt>
158
159 =head1 COPYRIGHT AND LICENSE
160
161 Copyright 2006 by Infinity Interactive, Inc.
162
163 L<http://www.iinteractive.com>
164
165 This library is free software; you can redistribute it and/or modify
166 it under the same terms as Perl itself.
167
168 =cut