2 package Moose::Autobox;
10 our $VERSION = '0.03';
15 (shift)->SUPER::import(
16 DEFAULT => 'Moose::Autobox::',
17 UNDEF => 'Moose::Autobox::Undef',
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);
30 package Moose::Autobox::SCALAR;
32 # this doesnt make sense, but
33 # I need to prevent Moose from
37 with 'Moose::Autobox::Scalar';
39 *does = \&Moose::Object::does;
41 package Moose::Autobox::ARRAY;
44 with 'Moose::Autobox::Array';
46 *does = \&Moose::Object::does;
48 package Moose::Autobox::HASH;
51 with 'Moose::Autobox::Hash';
53 *does = \&Moose::Object::does;
55 package Moose::Autobox::CODE;
58 with 'Moose::Autobox::Code';
60 *does = \&Moose::Object::does;
72 Moose::Autobox - Autoboxed for her pleasure
79 print 'Print squares from 1 to 10 : ';
80 print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
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.
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.
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.
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.
104 =head2 A quick word about autobox
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.
114 =head2 Is this for real? or just play?
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.
125 =item B<mixin_additional_role ($type, $role)>
127 This will mixin an additonal C<$role> into a certain C<$type>. The
128 types can be SCALAR, ARRAY, HASH or CODE.
130 This can be used to add additional methods to the types, see the
131 F<examples/units/> directory for some examples.
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
153 Stevan Little E<lt>stevan@iinteractive.comE<gt>
155 =head1 COPYRIGHT AND LICENSE
157 Copyright 2006 by Infinity Interactive, Inc.
159 L<http://www.iinteractive.com>
161 This library is free software; you can redistribute it and/or modify
162 it under the same terms as Perl itself.