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 | |
2f6b31a1 |
10 | our $VERSION = '0.02'; |
5f654d8e |
11 | |
8937074a |
12 | sub import { |
13 | eval q| |
2f6b31a1 |
14 | package # hide from PAUSE |
15 | SCALAR; |
31d40d73 |
16 | # NOTE: |
17 | # this doesnt make sense, but |
18 | # I need to prevent Moose from |
19 | # assiging to @ISA |
5272f13f |
20 | use base 'UNIVERSAL'; |
5f654d8e |
21 | use Moose; |
22 | with 'Moose::Autobox::Scalar'; |
23 | |
31d40d73 |
24 | *does = \&Moose::Object::does; |
25 | |
2f6b31a1 |
26 | package # hide from PAUSE |
27 | ARRAY; |
5272f13f |
28 | use base 'UNIVERSAL'; |
5f654d8e |
29 | use Moose; |
30 | with 'Moose::Autobox::Array'; |
31 | |
31d40d73 |
32 | *does = \&Moose::Object::does; |
33 | |
2f6b31a1 |
34 | package # hide from PAUSE |
35 | HASH; |
5272f13f |
36 | use base 'UNIVERSAL'; |
5f654d8e |
37 | use Moose; |
38 | with 'Moose::Autobox::Hash'; |
39 | |
31d40d73 |
40 | *does = \&Moose::Object::does; |
41 | |
2f6b31a1 |
42 | package # hide from PAUSE |
43 | CODE; |
5272f13f |
44 | use base 'UNIVERSAL'; |
5f654d8e |
45 | use Moose; |
31d40d73 |
46 | with 'Moose::Autobox::Code'; |
47 | |
48 | *does = \&Moose::Object::does; |
8937074a |
49 | |; |
50 | confess 'Could not create autobox packages because - ' . $@ if $@; |
51 | } |
5f654d8e |
52 | |
53 | 1; |
54 | |
55 | __END__ |
56 | |
57 | =pod |
58 | |
59 | =head1 NAME |
60 | |
8937074a |
61 | Moose::Autobox - Autoboxed for her pleasure |
5f654d8e |
62 | |
63 | =head1 SYNOPOSIS |
64 | |
39894c95 |
65 | use Moose::Autobox; |
66 | use autobox; |
31d40d73 |
67 | |
8937074a |
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. |
39894c95 |
81 | |
1972aa1b |
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 | |
5f654d8e |
85 | =head1 DESCRIPTION |
86 | |
8937074a |
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 | |
39894c95 |
110 | =head1 ROLES |
8937074a |
111 | |
112 | This is a rough diagram of the roles involved to get our 4 |
113 | autoboxed types (SCALAR, ARRAY, HASH & CODE). |
260cc81f |
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 | |
39894c95 |
129 | * indicates actual autoboxed types |
1972aa1b |
130 | |
131 | =head1 TODO |
132 | |
133 | =over 4 |
134 | |
135 | =item More docs |
136 | |
137 | =item More tests |
138 | |
139 | =back |
31d40d73 |
140 | |
141 | =head1 NOTES |
142 | |
8937074a |
143 | - String, Number & List are currently the only 'Value's. |
31d40d73 |
144 | |
145 | - Indexed is pretty much an interface, we probably will |
146 | need more of these (see Smalltalk Collection Trait |
147 | Refactoring) |
148 | |
5f654d8e |
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 | |
5f654d8e |
168 | =cut |