0.04
[gitmo/Moose-Autobox.git] / lib / Moose / Autobox.pm
index a36c1f5..6ca3141 100644 (file)
@@ -7,48 +7,62 @@ use warnings;
 use Carp        qw(confess);
 use Scalar::Util ();
 
-our $VERSION = '0.01';
-            
-sub import {
-    eval q|
-package SCALAR;
-
-# NOTE:
-# this doesnt make sense, but 
-# I need to prevent Moose from 
-# assiging to @ISA
-use base 'Moose::Autobox';
-
-use Moose;
-with 'Moose::Autobox::Scalar';
-
-*does = \&Moose::Object::does;
-
-package ARRAY;
-use base 'Moose::Autobox';
-use Moose;
-with 'Moose::Autobox::Array';
-
-*does = \&Moose::Object::does;
-
-package HASH;
-use base 'Moose::Autobox';
-use Moose;
-with 'Moose::Autobox::Hash';
+our $VERSION = '0.04';
 
-*does = \&Moose::Object::does;
+use base 'autobox';
 
-package CODE;
-use base 'Moose::Autobox';
-use Moose;
-with 'Moose::Autobox::Code';  
-
-*does = \&Moose::Object::does;
-  
-    |;
-    confess 'Could not create autobox packages because - ' . $@ if $@;
-}               
+use Moose::Autobox::Undef;
 
+sub import {
+    (shift)->SUPER::import(
+        DEFAULT => 'Moose::Autobox::',
+        UNDEF   => 'Moose::Autobox::Undef',
+    );
+}
+
+sub mixin_additional_role {
+    my ($class, $type, $role) = @_;
+    ($type =~ /SCALAR|ARRAY|HASH|CODE/)
+        || confess "Can only add additional roles to SCALAR, ARRAY, HASH or CODE";
+    ('Moose::Autobox::' . $type)->meta->_apply_all_roles($role);
+}
+
+{
+                        
+    package Moose::Autobox::SCALAR;
+    # NOTE:
+    # this doesnt make sense, but 
+    # I need to prevent Moose from 
+    # assiging to @ISA
+    use base 'UNIVERSAL';
+    use Moose;
+    with 'Moose::Autobox::Scalar';
+
+    *does = \&Moose::Object::does;
+
+    package Moose::Autobox::ARRAY;
+    use base 'UNIVERSAL';
+    use Moose;
+    with 'Moose::Autobox::Array';
+
+    *does = \&Moose::Object::does;
+
+    package Moose::Autobox::HASH;
+    use base 'UNIVERSAL';
+    use Moose;
+    with 'Moose::Autobox::Hash';
+
+    *does = \&Moose::Object::does;
+
+    package Moose::Autobox::CODE;
+    use base 'UNIVERSAL';
+    use Moose;
+    with 'Moose::Autobox::Code';  
+
+    *does = \&Moose::Object::does;            
+} 
+                 
 1;
 
 __END__
@@ -57,12 +71,11 @@ __END__
 
 =head1 NAME 
 
-Moose::Autobox - Autoboxed for her pleasure
+Moose::Autobox - Ruby ain't got nothin on us
 
 =head1 SYNOPOSIS
 
   use Moose::Autobox;
-  use autobox;
   
   print 'Print squares from 1 to 10 : ';
   print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
@@ -78,6 +91,9 @@ shiney new technology (L<Moose::Role>) to accomplish it's goals.
 Use this at your own risk. If it breaks the lamp in the living room
 and your mother yells at you, don't come complaining to me.
 
+Also, as this is so experimental, it's API should not be considered 
+to be stable. It could very well change in radical ways.
+
 =head1 DESCRIPTION
 
 Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH
@@ -103,34 +119,29 @@ possible. This may or may not be possible, depending on how well
 L<autobox> works out. At this point, I have high hopes for things
 but only time (and more tests and code) will tell.
 
-=head1 ROLES
-
-This is a rough diagram of the roles involved to get our 4 
-autoboxed types (SCALAR, ARRAY, HASH & CODE). 
-                                                          
-  +------------------------+-------------------------------+
-  |  Identity              |  Behavioral                   |
-  +------------------------+-------------------------------+
-  |  Item                  |                               |
-  |      Undef             |                               |
-  |      Defined           |                               |
-  |          Scalar*     <-|- String, Number <--+          |
-  |          Ref           |                    |-- Value  |
-  |              Array*  <-|- List <------------+          |
-  |              Hash*     |                               |
-  |              Code*     |                               |
-  |                        |                               |
-  +------------------------+-------------------------------+
-                                                          
-  * indicates actual autoboxed types
-  
-=head1 NOTES  
-  
-  - String, Number & List are currently the only 'Value's.
-  
-  - Indexed is pretty much an interface, we probably will 
-    need more of these (see Smalltalk Collection Trait 
-    Refactoring)
+=head1 METHODS
+
+=over 4
+
+=item B<mixin_additional_role ($type, $role)>
+
+This will mixin an additonal C<$role> into a certain C<$type>. The 
+types can be SCALAR, ARRAY, HASH or CODE.
+
+This can be used to add additional methods to the types, see the 
+F<examples/units/> directory for some examples.
+
+=back
+
+=head1 TODO
+
+=over 4
+
+=item More docs
+
+=item More tests
+
+=back
   
 =head1 BUGS
 
@@ -142,9 +153,17 @@ to cpan-RT.
 
 Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
+B<with contributions from:>
+
+Anders (Debolaz) Nor Berle
+
+Matt (mst) Trout
+
+renormalist
+
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006 by Infinity Interactive, Inc.
+Copyright 2006-2007 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>