foo
[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
10our $VERSION = '0.01';
11
8937074a 12sub import {
13 eval q|
5f654d8e 14package SCALAR;
31d40d73 15
16# NOTE:
17# this doesnt make sense, but
18# I need to prevent Moose from
19# assiging to @ISA
20use base 'Moose::Autobox';
21
5f654d8e 22use Moose;
23with 'Moose::Autobox::Scalar';
24
31d40d73 25*does = \&Moose::Object::does;
26
5f654d8e 27package ARRAY;
31d40d73 28use base 'Moose::Autobox';
5f654d8e 29use Moose;
30with 'Moose::Autobox::Array';
31
31d40d73 32*does = \&Moose::Object::does;
33
5f654d8e 34package HASH;
31d40d73 35use base 'Moose::Autobox';
5f654d8e 36use Moose;
37with 'Moose::Autobox::Hash';
38
31d40d73 39*does = \&Moose::Object::does;
40
5f654d8e 41package CODE;
31d40d73 42use base 'Moose::Autobox';
5f654d8e 43use Moose;
31d40d73 44with 'Moose::Autobox::Code';
45
46*does = \&Moose::Object::does;
47
8937074a 48 |;
49 confess 'Could not create autobox packages because - ' . $@ if $@;
50}
5f654d8e 51
521;
53
54__END__
55
56=pod
57
58=head1 NAME
59
8937074a 60Moose::Autobox - Autoboxed for her pleasure
5f654d8e 61
62=head1 SYNOPOSIS
63
39894c95 64 use Moose::Autobox;
65 use autobox;
31d40d73 66
8937074a 67 print 'Print squares from 1 to 10 : ';
68 print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
69
70=head1 CAVEAT
71
72First, a warning.
73
74This module is very very very very very very very experimental. It
75makes use of a very experimental module (L<autobox>) and uses some
76shiney new technology (L<Moose::Role>) to accomplish it's goals.
77
78Use this at your own risk. If it breaks the lamp in the living room
79and your mother yells at you, don't come complaining to me.
39894c95 80
5f654d8e 81=head1 DESCRIPTION
82
8937074a 83Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH
84& CODE for use with L<autobox>. It does this using a hierarchy of
85roles in a manner similar to what Perl 6 I<might> do. This module,
86like L<Class::MOP> and L<Moose>, was inspired by my work on the
87Perl 6 Object Space, and the 'core types' implemented there.
88
89=head2 A quick word about autobox
90
91The L<autobox> module provides the ability for calling 'methods'
92on normal Perl values like Scalars, Arrays, Hashes and Code
93references. This gives the illusion that Perl's types are first-class
94objects. However, this is only an illusion, albeit a very nice one.
95I created this module because L<autobox> itself does not actually
96provide an implementation for the Perl types but instead only provides
97the 'hooks' for others to add implementation too.
98
99=head2 Is this for real? or just play?
100
101My intent is to try and make this module as production worthy as
102possible. This may or may not be possible, depending on how well
103L<autobox> works out. At this point, I have high hopes for things
104but only time (and more tests and code) will tell.
105
39894c95 106=head1 ROLES
8937074a 107
108This is a rough diagram of the roles involved to get our 4
109autoboxed types (SCALAR, ARRAY, HASH & CODE).
260cc81f 110
111 +------------------------+-------------------------------+
112 | Identity | Behavioral |
113 +------------------------+-------------------------------+
114 | Item | |
115 | Undef | |
116 | Defined | |
117 | Scalar* <-|- String, Number <--+ |
118 | Ref | |-- Value |
119 | Array* <-|- List <------------+ |
120 | Hash* | |
121 | Code* | |
122 | | |
123 +------------------------+-------------------------------+
124
39894c95 125 * indicates actual autoboxed types
31d40d73 126
127=head1 NOTES
128
8937074a 129 - String, Number & List are currently the only 'Value's.
31d40d73 130
131 - Indexed is pretty much an interface, we probably will
132 need more of these (see Smalltalk Collection Trait
133 Refactoring)
134
5f654d8e 135=head1 BUGS
136
137All complex software has bugs lurking in it, and this module is no
138exception. If you find a bug please either email me, or add the bug
139to cpan-RT.
140
141=head1 AUTHOR
142
143Stevan Little E<lt>stevan@iinteractive.comE<gt>
144
145=head1 COPYRIGHT AND LICENSE
146
147Copyright 2006 by Infinity Interactive, Inc.
148
149L<http://www.iinteractive.com>
150
151This library is free software; you can redistribute it and/or modify
152it under the same terms as Perl itself.
153
5f654d8e 154=cut