X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FAutobox.pm;h=e56e56f62fd19caae022e2e540b01371a157c9dc;hb=0a73bc93825d51284658170361933d2d329462eb;hp=6940facb5333678bf7adfb9f025dd1217aed5ddc;hpb=5272f13f684d461d95aa45de22d8776a98c03c64;p=gitmo%2FMoose-Autobox.git diff --git a/lib/Moose/Autobox.pm b/lib/Moose/Autobox.pm index 6940fac..e56e56f 100644 --- a/lib/Moose/Autobox.pm +++ b/lib/Moose/Autobox.pm @@ -6,49 +6,72 @@ use warnings; use Carp qw(confess); use Scalar::Util (); +use Moose::Util (); + +our $VERSION = '0.08'; + +use base 'autobox'; + +use Moose::Autobox::Undef; -our $VERSION = '0.01'; - sub import { - eval q| -package SCALAR; + (shift)->SUPER::import( + DEFAULT => 'Moose::Autobox::', + UNDEF => 'Moose::Autobox::Undef', + ); +} -# NOTE: -# this doesnt make sense, but -# I need to prevent Moose from -# assiging to @ISA -use base 'UNIVERSAL'; +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::Util::apply_all_roles(('Moose::Autobox::' . $type)->meta, ($role)); +} -use Moose; -with 'Moose::Autobox::Scalar'; +{ + + package Moose::Autobox::SCALAR; -*does = \&Moose::Object::does; + use Moose::Autobox::Scalar; -package ARRAY; -use base 'UNIVERSAL'; -use Moose; -with 'Moose::Autobox::Array'; + use metaclass 'Moose::Meta::Class'; -*does = \&Moose::Object::does; + Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Scalar')); -package HASH; -use base 'UNIVERSAL'; -use Moose; -with 'Moose::Autobox::Hash'; + *does = \&Moose::Object::does; -*does = \&Moose::Object::does; + package Moose::Autobox::ARRAY; -package CODE; -use base 'UNIVERSAL'; -use Moose; -with 'Moose::Autobox::Code'; + use Moose::Autobox::Array; -*does = \&Moose::Object::does; - - |; - confess 'Could not create autobox packages because - ' . $@ if $@; -} + use metaclass 'Moose::Meta::Class'; + + Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Array')); + + *does = \&Moose::Object::does; + + package Moose::Autobox::HASH; + + use Moose::Autobox::Hash; + + use metaclass 'Moose::Meta::Class'; + + Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Hash')); + + *does = \&Moose::Object::does; + package Moose::Autobox::CODE; + + use Moose::Autobox::Code; + + use metaclass 'Moose::Meta::Class'; + + Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Code')); + + *does = \&Moose::Object::does; + +} + 1; __END__ @@ -57,27 +80,15 @@ __END__ =head1 NAME -Moose::Autobox - Autoboxed for her pleasure +Moose::Autobox - Autoboxed wrappers for Native Perl datatypes =head1 SYNOPOSIS use Moose::Autobox; - use autobox; 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 @@ -98,39 +109,51 @@ 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 | - +------------------------+-------------------------------+ - | 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) +Several people are using this module in serious applications and +it seems to be quite stable. The underlying technologies of L +and L are also considered stable. There is some performance +hit, but as I am fond of saying, nothing in life is free. If you have +any questions regarding this module, either email me, or stop by #moose +on irc.perl.org and ask around. + +=head2 Adding additional methods + +B asks L to use the B namespace +prefix so as to avoid stepping on the toes of other L modules. This +means that if you want to add methods to a particular perl type +(i.e. - monkeypatch), then you must do this: + + sub Moose::Autobox::SCALAR::bar { 42 } + +instead of this: + + sub SCALAR::bar { 42 } + +as you would with vanilla autobox. + +=head1 METHODS + +=over 4 + +=item B + +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 directory for some examples. + +=back + +=head1 TODO + +=over 4 + +=item More docs + +=item More tests + +=back =head1 BUGS @@ -142,9 +165,17 @@ to cpan-RT. Stevan Little Estevan@iinteractive.comE +B + +Anders (Debolaz) Nor Berle + +Matt (mst) Trout + +renormalist + =head1 COPYRIGHT AND LICENSE -Copyright 2006 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L