more examples
[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
8937074a 14sub import {
7dad2765 15 (shift)->SUPER::import(
16 DEFAULT => 'Moose::Autobox::',
17 UNDEF => 'Moose::Autobox::Undef',
18 );
19}
7dad2765 20
244bd352 21sub 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 641;
65
66__END__
67
68=pod
69
70=head1 NAME
71
8937074a 72Moose::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
84First, a warning.
85
86This module is very very very very very very very experimental. It
87makes use of a very experimental module (L<autobox>) and uses some
88shiney new technology (L<Moose::Role>) to accomplish it's goals.
89
90Use this at your own risk. If it breaks the lamp in the living room
91and your mother yells at you, don't come complaining to me.
39894c95 92
1972aa1b 93Also, as this is so experimental, it's API should not be considered
94to be stable. It could very well change in radical ways.
95
5f654d8e 96=head1 DESCRIPTION
97
8937074a 98Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH
99& CODE for use with L<autobox>. It does this using a hierarchy of
100roles in a manner similar to what Perl 6 I<might> do. This module,
101like L<Class::MOP> and L<Moose>, was inspired by my work on the
102Perl 6 Object Space, and the 'core types' implemented there.
103
104=head2 A quick word about autobox
105
106The L<autobox> module provides the ability for calling 'methods'
107on normal Perl values like Scalars, Arrays, Hashes and Code
108references. This gives the illusion that Perl's types are first-class
109objects. However, this is only an illusion, albeit a very nice one.
110I created this module because L<autobox> itself does not actually
111provide an implementation for the Perl types but instead only provides
112the 'hooks' for others to add implementation too.
113
114=head2 Is this for real? or just play?
115
116My intent is to try and make this module as production worthy as
117possible. This may or may not be possible, depending on how well
118L<autobox> works out. At this point, I have high hopes for things
119but 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
127This will mixin an additonal C<$role> into a certain C<$type>. The
128types can be SCALAR, ARRAY, HASH or CODE.
129
130This can be used to add additional methods to the types, see the
131F<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
147All complex software has bugs lurking in it, and this module is no
148exception. If you find a bug please either email me, or add the bug
149to cpan-RT.
150
151=head1 AUTHOR
152
153Stevan Little E<lt>stevan@iinteractive.comE<gt>
154
155=head1 COPYRIGHT AND LICENSE
156
157Copyright 2006 by Infinity Interactive, Inc.
158
159L<http://www.iinteractive.com>
160
161This library is free software; you can redistribute it and/or modify
162it under the same terms as Perl itself.
163
5f654d8e 164=cut