-Revision history for Perl extension Moose::Autobox
\ No newline at end of file
+Revision history for Perl extension Moose::Autobox
+
+0.01
+ - Autoboxing - all the cool kids are doing it ;)
\ No newline at end of file
our $VERSION = '0.01';
-#sub import {
-# eval q|
+sub import {
+ eval q|
package SCALAR;
# NOTE:
*does = \&Moose::Object::does;
-# |;
-# confess 'Could not create autobox packages because - ' . $@ if $@;
-#}
+ |;
+ confess 'Could not create autobox packages because - ' . $@ if $@;
+}
1;
=head1 NAME
-Moose::Autobox - autoboxed for her pleasure
+Moose::Autobox - Autoboxed for her pleasure
=head1 SYNOPOSIS
use Moose::Autobox;
use autobox;
- 'Print squares from 1 to 10'->print;
- [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ')->print;
+ print 'Print squares from 1 to 10 : ';
+ print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
+
+=head1 CAVEAT
+
+First, a warning.
+
+This module is very very very very very very very experimental. It
+makes use of a very experimental module (L<autobox>) and uses some
+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.
=head1 DESCRIPTION
+Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH
+& CODE for use with L<autobox>. It does this using a hierarchy of
+roles in a manner similar to what Perl 6 I<might> do. This module,
+like L<Class::MOP> and L<Moose>, was inspired by my work on the
+Perl 6 Object Space, and the 'core types' implemented there.
+
+=head2 A quick word about autobox
+
+The L<autobox> module provides the ability for calling 'methods'
+on normal Perl values like Scalars, Arrays, Hashes and Code
+references. This gives the illusion that Perl's types are first-class
+objects. However, this is only an illusion, albeit a very nice one.
+I created this module because L<autobox> itself does not actually
+provide an implementation for the Perl types but instead only provides
+the 'hooks' for others to add implementation too.
+
+=head2 Is this for real? or just play?
+
+My intent is to try and make this module as production worthy as
+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 |
=head1 NOTES
- - String, Number & List are currently the only Values.
+ - 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
=head1 DESCRIPTION
+This is a role to describe operations on the Array type.
+
=head1 METHODS
=over 4
=back
-=head2 Indexed
+=head2 Moose::Autobox::Indexed implementation
=over 4
=back
-=head2 List
+=head2 Moose::Autobox::List implementation
=over 4
=head1 DESCRIPTION
+This is a role to describe operations on the Code type.
+
=head1 METHODS
=over 4
=head1 DESCRIPTION
+This is a role to describes a defined value.
+
=head1 METHODS
=over 4
use Moose::Autobox;
use autobox;
- { one => 1, two => 2 }->keys->join(', ')->print; # prints 'one, two'
+ print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two'
=head1 DESCRIPTION
+This is a role to describes a Hash value.
+
=head1 METHODS
=over 4
=back
-=head2 Indexed
+=head2 Moose::Autobox::Indexed implementation
=over 4
=head1 DESCRIPTION
+This is a role to describes an collection whose values can be
+accessed by a key of some kind.
+
+The role is entirely abstract, those which implement it must
+supply all it's methods. Currently both L<Moose::Autobox::Array>
+and L<Moose::Autobox::Hash> implement this role.
+
=head1 METHODS
=over 4
=head1 DESCRIPTION
+This is the root of our role hierarchy.
+
=head1 METHODS
=over 4
=head1 DESCRIPTION
+This is a role to describes a List interface. This is not
+meant to be any specific Perl type, but instead an interface
+that certain Perl types might implement. Currenly only
+L<Moose::Autobox::Array> implements this.
+
=head1 METHODS
=over 4
=head1 DESCRIPTION
+This is a role to describes a Numeric value.
+
=head1 METHODS
=over 4
=head1 DESCRIPTION
+This is a role to describes a reference value.
+
=head1 METHODS
=over 4
=head1 DESCRIPTION
+This is a role to describes a Scalar value, which is defined
+as the combination (union sort of) of a String and a Number.
+
=head1 METHODS
=over 4
=head1 DESCRIPTION
+This is a role to describes a String value.
+
=head1 METHODS
=over 4
=head1 DESCRIPTION
+This is a role to describes a undefined value.
+
=head1 METHODS
=over 4
use Moose::Autobox;
use autobox;
- 5->print; # prints 5
-
- # excute a sub on the value
- 10->do(sub { $_ + 15 })->print; # prints 25
+ # execute a sub on the value
+ print 10->do(sub { $_ * $_ }); # prints 100
=head1 DESCRIPTION
+This is a role to describes a defined (non-reference) Perl value.
+
=head1 METHODS
=over 4
=item B<meta>
-=item B<do>
+=item B<do (\&block)>
=back
use strict;
use warnings;
-use Test::More tests => 20;
+use Test::More tests => 22;
BEGIN {
use_ok('Moose::Autobox');
}
-ok(SCALAR->does('Moose::Autobox::Scalar'), '... SCALAR does Moose::Autobox::Scalar');
- ok(SCALAR->does('Moose::Autobox::Value'), '... SCALAR does Moose::Autobox::Value');
- ok(SCALAR->does('Moose::Autobox::Defined'), '... SCALAR does Moose::Autobox::Defined');
- ok(SCALAR->does('Moose::Autobox::Item'), '... SCALAR does Moose::Autobox::Item');
+ok(SCALAR->does('Moose::Autobox::Scalar'), '... SCALAR does Moose::Autobox::Scalar');
+ ok(SCALAR->does('Moose::Autobox::String'), '... SCALAR does Moose::Autobox::String');
+ ok(SCALAR->does('Moose::Autobox::Number'), '... SCALAR does Moose::Autobox::Number');
+ ok(SCALAR->does('Moose::Autobox::Value'), '... SCALAR does Moose::Autobox::Value');
+ ok(SCALAR->does('Moose::Autobox::Defined'), '... SCALAR does Moose::Autobox::Defined');
+ ok(SCALAR->does('Moose::Autobox::Item'), '... SCALAR does Moose::Autobox::Item');
-ok(ARRAY->does('Moose::Autobox::Array'), '... ARRAY does Moose::Autobox::Array');
- ok(ARRAY->does('Moose::Autobox::List'), '... ARRAY does Moose::Autobox::List');
- ok(ARRAY->does('Moose::Autobox::Indexed'), '... ARRAY does Moose::Autobox::Indexed');
- ok(ARRAY->does('Moose::Autobox::Ref'), '... ARRAY does Moose::Autobox::Ref');
- ok(ARRAY->does('Moose::Autobox::Defined'), '... ARRAY does Moose::Autobox::Defined');
- ok(ARRAY->does('Moose::Autobox::Item'), '... ARRAY does Moose::Autobox::Item');
-
-ok(HASH->does('Moose::Autobox::Hash'), '... HASH does Moose::Autobox::Hash');
- ok(HASH->does('Moose::Autobox::Indexed'), '... HASH does Moose::Autobox::Indexed');
- ok(HASH->does('Moose::Autobox::Ref'), '... HASH does Moose::Autobox::Ref');
- ok(HASH->does('Moose::Autobox::Defined'), '... HASH does Moose::Autobox::Defined');
- ok(HASH->does('Moose::Autobox::Item'), '... HASH does Moose::Autobox::Item');
-
-ok(CODE->does('Moose::Autobox::Code'), '... CODE does Moose::Autobox::Code');
- ok(CODE->does('Moose::Autobox::Ref'), '... CODE does Moose::Autobox::Ref');
- ok(CODE->does('Moose::Autobox::Defined'), '... CODE does Moose::Autobox::Defined');
- ok(CODE->does('Moose::Autobox::Item'), '... CODE does Moose::Autobox::Item');
+ok(ARRAY->does('Moose::Autobox::Array'), '... ARRAY does Moose::Autobox::Array');
+ ok(ARRAY->does('Moose::Autobox::List'), '... ARRAY does Moose::Autobox::List');
+ ok(ARRAY->does('Moose::Autobox::Indexed'), '... ARRAY does Moose::Autobox::Indexed');
+ ok(ARRAY->does('Moose::Autobox::Ref'), '... ARRAY does Moose::Autobox::Ref');
+ ok(ARRAY->does('Moose::Autobox::Defined'), '... ARRAY does Moose::Autobox::Defined');
+ ok(ARRAY->does('Moose::Autobox::Item'), '... ARRAY does Moose::Autobox::Item');
+
+ok(HASH->does('Moose::Autobox::Hash'), '... HASH does Moose::Autobox::Hash');
+ ok(HASH->does('Moose::Autobox::Indexed'), '... HASH does Moose::Autobox::Indexed');
+ ok(HASH->does('Moose::Autobox::Ref'), '... HASH does Moose::Autobox::Ref');
+ ok(HASH->does('Moose::Autobox::Defined'), '... HASH does Moose::Autobox::Defined');
+ ok(HASH->does('Moose::Autobox::Item'), '... HASH does Moose::Autobox::Item');
+
+ok(CODE->does('Moose::Autobox::Code'), '... CODE does Moose::Autobox::Code');
+ ok(CODE->does('Moose::Autobox::Ref'), '... CODE does Moose::Autobox::Ref');
+ ok(CODE->does('Moose::Autobox::Defined'), '... CODE does Moose::Autobox::Defined');
+ ok(CODE->does('Moose::Autobox::Item'), '... CODE does Moose::Autobox::Item');