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