2 package Moose::Autobox;
10 our $VERSION = '0.05';
14 use Moose::Autobox::Undef;
17 (shift)->SUPER::import(
18 DEFAULT => 'Moose::Autobox::',
19 UNDEF => 'Moose::Autobox::Undef',
23 sub mixin_additional_role {
24 my ($class, $type, $role) = @_;
25 ($type =~ /SCALAR|ARRAY|HASH|CODE/)
26 || confess "Can only add additional roles to SCALAR, ARRAY, HASH or CODE";
27 ('Moose::Autobox::' . $type)->meta->_apply_all_roles($role);
32 package Moose::Autobox::SCALAR;
34 use Moose::Autobox::Scalar;
36 use metaclass 'Moose::Meta::Class';
38 __PACKAGE__->meta->_apply_all_roles('Moose::Autobox::Scalar');
40 *does = \&Moose::Object::does;
42 package Moose::Autobox::ARRAY;
44 use Moose::Autobox::Array;
46 use metaclass 'Moose::Meta::Class';
48 __PACKAGE__->meta->_apply_all_roles('Moose::Autobox::Array');
50 *does = \&Moose::Object::does;
52 package Moose::Autobox::HASH;
54 use Moose::Autobox::Hash;
56 use metaclass 'Moose::Meta::Class';
58 __PACKAGE__->meta->_apply_all_roles('Moose::Autobox::Hash');
60 *does = \&Moose::Object::does;
62 package Moose::Autobox::CODE;
64 use Moose::Autobox::Code;
66 use metaclass 'Moose::Meta::Class';
68 __PACKAGE__->meta->_apply_all_roles('Moose::Autobox::Code');
70 *does = \&Moose::Object::does;
82 Moose::Autobox - Ruby ain't got nothin on us
88 print 'Print squares from 1 to 10 : ';
89 print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
95 This module is very very very very very very very experimental. It
96 makes use of a very experimental module (L<autobox>) and uses some
97 shiney new technology (L<Moose::Role>) to accomplish it's goals.
99 Use this at your own risk. If it breaks the lamp in the living room
100 and your mother yells at you, don't come complaining to me.
102 Also, as this is so experimental, it's API should not be considered
103 to be stable. It could very well change in radical ways.
107 Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH
108 & CODE for use with L<autobox>. It does this using a hierarchy of
109 roles in a manner similar to what Perl 6 I<might> do. This module,
110 like L<Class::MOP> and L<Moose>, was inspired by my work on the
111 Perl 6 Object Space, and the 'core types' implemented there.
113 =head2 A quick word about autobox
115 The L<autobox> module provides the ability for calling 'methods'
116 on normal Perl values like Scalars, Arrays, Hashes and Code
117 references. This gives the illusion that Perl's types are first-class
118 objects. However, this is only an illusion, albeit a very nice one.
119 I created this module because L<autobox> itself does not actually
120 provide an implementation for the Perl types but instead only provides
121 the 'hooks' for others to add implementation too.
123 =head2 Is this for real? or just play?
125 My intent is to try and make this module as production worthy as
126 possible. This may or may not be possible, depending on how well
127 L<autobox> works out. At this point, I have high hopes for things
128 but only time (and more tests and code) will tell.
134 =item B<mixin_additional_role ($type, $role)>
136 This will mixin an additonal C<$role> into a certain C<$type>. The
137 types can be SCALAR, ARRAY, HASH or CODE.
139 This can be used to add additional methods to the types, see the
140 F<examples/units/> directory for some examples.
156 All complex software has bugs lurking in it, and this module is no
157 exception. If you find a bug please either email me, or add the bug
162 Stevan Little E<lt>stevan@iinteractive.comE<gt>
164 B<with contributions from:>
166 Anders (Debolaz) Nor Berle
172 =head1 COPYRIGHT AND LICENSE
174 Copyright 2006-2007 by Infinity Interactive, Inc.
176 L<http://www.iinteractive.com>
178 This library is free software; you can redistribute it and/or modify
179 it under the same terms as Perl itself.