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