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