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