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