From: Stevan Little Date: Fri, 9 Jun 2006 20:40:44 +0000 (+0000) Subject: foo X-Git-Tag: 0_02~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8937074ab98e81964dee9ccf9bbd939ebf3252a0;hp=260cc81f7ab424f417900ab1c44b734b339f9d9e;p=gitmo%2FMoose-Autobox.git foo --- diff --git a/Changes b/Changes index 64aa008..94f667f 100644 --- a/Changes +++ b/Changes @@ -1 +1,4 @@ -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 diff --git a/lib/Moose/Autobox.pm b/lib/Moose/Autobox.pm index 42e0dd6..a36c1f5 100644 --- a/lib/Moose/Autobox.pm +++ b/lib/Moose/Autobox.pm @@ -9,8 +9,8 @@ use Scalar::Util (); our $VERSION = '0.01'; -#sub import { -# eval q| +sub import { + eval q| package SCALAR; # NOTE: @@ -45,9 +45,9 @@ with 'Moose::Autobox::Code'; *does = \&Moose::Object::does; -# |; -# confess 'Could not create autobox packages because - ' . $@ if $@; -#} + |; + confess 'Could not create autobox packages because - ' . $@ if $@; +} 1; @@ -57,19 +57,56 @@ __END__ =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) and uses some +shiney new technology (L) 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. It does this using a hierarchy of +roles in a manner similar to what Perl 6 I do. This module, +like L and L, 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 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 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 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 | @@ -89,7 +126,7 @@ Moose::Autobox - autoboxed for her pleasure =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 diff --git a/lib/Moose/Autobox/Array.pm b/lib/Moose/Autobox/Array.pm index 6bfda4a..38e94f1 100644 --- a/lib/Moose/Autobox/Array.pm +++ b/lib/Moose/Autobox/Array.pm @@ -130,6 +130,8 @@ Moose::Autobox::Array - the Array role =head1 DESCRIPTION +This is a role to describe operations on the Array type. + =head1 METHODS =over 4 @@ -150,7 +152,7 @@ Moose::Autobox::Array - the Array role =back -=head2 Indexed +=head2 Moose::Autobox::Indexed implementation =over 4 @@ -168,7 +170,7 @@ Moose::Autobox::Array - the Array role =back -=head2 List +=head2 Moose::Autobox::List implementation =over 4 diff --git a/lib/Moose/Autobox/Code.pm b/lib/Moose/Autobox/Code.pm index aa694cb..80ecbe1 100644 --- a/lib/Moose/Autobox/Code.pm +++ b/lib/Moose/Autobox/Code.pm @@ -55,6 +55,8 @@ Moose::Autobox::Code - the Code role =head1 DESCRIPTION +This is a role to describe operations on the Code type. + =head1 METHODS =over 4 diff --git a/lib/Moose/Autobox/Defined.pm b/lib/Moose/Autobox/Defined.pm index e8c285b..3fb2820 100644 --- a/lib/Moose/Autobox/Defined.pm +++ b/lib/Moose/Autobox/Defined.pm @@ -24,6 +24,8 @@ Moose::Autobox::Defined - the Defined role =head1 DESCRIPTION +This is a role to describes a defined value. + =head1 METHODS =over 4 diff --git a/lib/Moose/Autobox/Hash.pm b/lib/Moose/Autobox/Hash.pm index f8766b9..5c318dc 100644 --- a/lib/Moose/Autobox/Hash.pm +++ b/lib/Moose/Autobox/Hash.pm @@ -58,10 +58,12 @@ Moose::Autobox::Hash - the Hash role 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 @@ -72,7 +74,7 @@ Moose::Autobox::Hash - the Hash role =back -=head2 Indexed +=head2 Moose::Autobox::Indexed implementation =over 4 diff --git a/lib/Moose/Autobox/Indexed.pm b/lib/Moose/Autobox/Indexed.pm index d3706cf..6c3a2de 100644 --- a/lib/Moose/Autobox/Indexed.pm +++ b/lib/Moose/Autobox/Indexed.pm @@ -29,6 +29,13 @@ Moose::Autobox::Indexed - the Indexed role =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 +and L implement this role. + =head1 METHODS =over 4 diff --git a/lib/Moose/Autobox/Item.pm b/lib/Moose/Autobox/Item.pm index 0cb2092..a80b9d2 100644 --- a/lib/Moose/Autobox/Item.pm +++ b/lib/Moose/Autobox/Item.pm @@ -22,6 +22,8 @@ Moose::Autobox::Item - the Item role =head1 DESCRIPTION +This is the root of our role hierarchy. + =head1 METHODS =over 4 diff --git a/lib/Moose/Autobox/List.pm b/lib/Moose/Autobox/List.pm index b3f9048..434b0f9 100644 --- a/lib/Moose/Autobox/List.pm +++ b/lib/Moose/Autobox/List.pm @@ -54,6 +54,11 @@ Moose::Autobox::List - the List role =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 implements this. + =head1 METHODS =over 4 diff --git a/lib/Moose/Autobox/Number.pm b/lib/Moose/Autobox/Number.pm index a2e30ad..9f42445 100644 --- a/lib/Moose/Autobox/Number.pm +++ b/lib/Moose/Autobox/Number.pm @@ -22,6 +22,8 @@ Moose::Autobox::Number - the Number role =head1 DESCRIPTION +This is a role to describes a Numeric value. + =head1 METHODS =over 4 diff --git a/lib/Moose/Autobox/Ref.pm b/lib/Moose/Autobox/Ref.pm index 42f3047..7d83e88 100644 --- a/lib/Moose/Autobox/Ref.pm +++ b/lib/Moose/Autobox/Ref.pm @@ -22,6 +22,8 @@ Moose::Autobox::Ref - the Ref role =head1 DESCRIPTION +This is a role to describes a reference value. + =head1 METHODS =over 4 diff --git a/lib/Moose/Autobox/Scalar.pm b/lib/Moose/Autobox/Scalar.pm index 5fe4ec9..ea035d1 100644 --- a/lib/Moose/Autobox/Scalar.pm +++ b/lib/Moose/Autobox/Scalar.pm @@ -23,6 +23,9 @@ Moose::Autobox::Scalar - the Scalar role =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 diff --git a/lib/Moose/Autobox/String.pm b/lib/Moose/Autobox/String.pm index 09d63a6..bf048a2 100644 --- a/lib/Moose/Autobox/String.pm +++ b/lib/Moose/Autobox/String.pm @@ -39,6 +39,8 @@ Moose::Autobox::String - the String role =head1 DESCRIPTION +This is a role to describes a String value. + =head1 METHODS =over 4 diff --git a/lib/Moose/Autobox/Undef.pm b/lib/Moose/Autobox/Undef.pm index 62a6bc8..3d2b7d3 100644 --- a/lib/Moose/Autobox/Undef.pm +++ b/lib/Moose/Autobox/Undef.pm @@ -24,6 +24,8 @@ Moose::Autobox::Undef - the Undef role =head1 DESCRIPTION +This is a role to describes a undefined value. + =head1 METHODS =over 4 diff --git a/lib/Moose/Autobox/Value.pm b/lib/Moose/Autobox/Value.pm index d63316f..d41d73d 100644 --- a/lib/Moose/Autobox/Value.pm +++ b/lib/Moose/Autobox/Value.pm @@ -25,20 +25,20 @@ Moose::Autobox::Value - the Value role 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 -=item B +=item B =back diff --git a/t/002_example.t b/t/002_example.t index 553950d..332b8fe 100644 --- a/t/002_example.t +++ b/t/002_example.t @@ -3,34 +3,36 @@ 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');