package Moose::Autobox;
-
+use 5.006;
use strict;
use warnings;
use Carp qw(confess);
use Scalar::Util ();
+use Moose::Util ();
-our $VERSION = '0.03';
+our $VERSION = '0.11';
use base 'autobox';
+use Moose::Autobox::Undef;
+
sub import {
(shift)->SUPER::import(
DEFAULT => 'Moose::Autobox::',
UNDEF => 'Moose::Autobox::Undef',
);
}
-
-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__
-
-=pod
-
-=head1 NAME
-
-Moose::Autobox - Autoboxed for her pleasure
-
-=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<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.
-
-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
-& 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 |
- +------------------------+-------------------------------+
- | Item | |
- | Undef | |
- | Defined | |
- | Scalar* <-|- String, Number <--+ |
- | Ref | |-- Value |
- | Array* <-|- List <------------+ |
- | Hash* | |
- | Code* | |
- | | |
- +------------------------+-------------------------------+
-
- * indicates actual autoboxed types
-
-=head1 TODO
-
-=over 4
-
-=item More docs
-
-=item More tests
-
-=back
-
-=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 BUGS
-
-All complex software has bugs lurking in it, and this module is no
-exception. If you find a bug please either email me, or add the bug
-to cpan-RT.
-
-=head1 AUTHOR
-
-Stevan Little E<lt>stevan@iinteractive.comE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2006 by Infinity Interactive, Inc.
-
-L<http://www.iinteractive.com>
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-package Moose::Autobox;
-
-use strict;
-use warnings;
-use Carp qw(confess);
-use Scalar::Util ();
+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));
+}
-our $VERSION = '0.02';
+{
-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__
-
-=pod
-
-=head1 NAME
-
-Moose::Autobox - Autoboxed for her pleasure
-
-=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<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.
-
-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
-& 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 |
- +------------------------+-------------------------------+
- | Item | |
- | Undef | |
- | Defined | |
- | Scalar* <-|- String, Number <--+ |
- | Ref | |-- Value |
- | Array* <-|- List <------------+ |
- | Hash* | |
- | Code* | |
- | | |
- +------------------------+-------------------------------+
-
- * indicates actual autoboxed types
-
-=head1 TODO
-
-=over 4
-
-=item More docs
-
-=item More tests
-
-=back
-
-=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 BUGS
+ package Moose::Autobox::SCALAR;
-All complex software has bugs lurking in it, and this module is no
-exception. If you find a bug please either email me, or add the bug
-to cpan-RT.
+ use Moose::Autobox::Scalar;
-=head1 AUTHOR
+ use metaclass 'Moose::Meta::Class';
-Stevan Little E<lt>stevan@iinteractive.comE<gt>
+ Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Scalar'));
-=head1 COPYRIGHT AND LICENSE
+ *does = \&Moose::Object::does;
-Copyright 2006 by Infinity Interactive, Inc.
+ package Moose::Autobox::ARRAY;
-L<http://www.iinteractive.com>
+ use Moose::Autobox::Array;
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
+ use metaclass 'Moose::Meta::Class';
-=cut
+ Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Array'));
-package Moose::Autobox;
+ *does = \&Moose::Object::does;
-use strict;
-use warnings;
+ package Moose::Autobox::HASH;
-use Carp qw(confess);
-use Scalar::Util ();
+ use Moose::Autobox::Hash;
-our $VERSION = '0.02';
-
-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';
+ use metaclass 'Moose::Meta::Class';
-*does = \&Moose::Object::does;
+ Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Hash'));
-package Moose::Autobox::ARRAY;
-use base 'UNIVERSAL';
-use Moose;
-with 'Moose::Autobox::Array';
+ *does = \&Moose::Object::does;
-*does = \&Moose::Object::does;
+ package Moose::Autobox::CODE;
-package Moose::Autobox::HASH;
-use base 'UNIVERSAL';
-use Moose;
-with 'Moose::Autobox::Hash';
+ use Moose::Autobox::Code;
-*does = \&Moose::Object::does;
+ use metaclass 'Moose::Meta::Class';
-package Moose::Autobox::CODE;
-use base 'UNIVERSAL';
-use Moose;
-with 'Moose::Autobox::Code';
+ Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Code'));
-*does = \&Moose::Object::does;
+ *does = \&Moose::Object::does;
+
+}
1;
=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<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.
-
-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
=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 |
- +------------------------+-------------------------------+
- | Item | |
- | Undef | |
- | Defined | |
- | Scalar* <-|- String, Number <--+ |
- | Ref | |-- Value |
- | Array* <-|- List <------------+ |
- | Hash* | |
- | Code* | |
- | | |
- +------------------------+-------------------------------+
-
- * indicates actual autoboxed types
-
-=head1 TODO
-
-=over 4
-
-=item More docs
-
-=item More tests
-
-=back
-
-=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 BUGS
-
-All complex software has bugs lurking in it, and this module is no
-exception. If you find a bug please either email me, or add the bug
-to cpan-RT.
-
-=head1 AUTHOR
-
-Stevan Little E<lt>stevan@iinteractive.comE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2006 by Infinity Interactive, Inc.
-
-L<http://www.iinteractive.com>
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-package Moose::Autobox;
-
-use strict;
-use warnings;
-
-use Carp qw(confess);
-use Scalar::Util ();
-
-our $VERSION = '0.02';
-
-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__
-
-=pod
-
-=head1 NAME
-
-Moose::Autobox - Autoboxed for her pleasure
+Several people are using this module in serious applications and
+it seems to be quite stable. The underlying technologies of L<autobox>
+and L<Moose::Role> 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.
-=head1 SYNOPOSIS
-
- use Moose::Autobox;
- use autobox;
-
- print 'Print squares from 1 to 10 : ';
- print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
+=head2 Adding additional methods
-=head1 CAVEAT
+B<Moose::Autobox> asks L<autobox> to use the B<Moose::Autobox::*> namespace
+prefix so as to avoid stepping on the toes of other L<autobox> modules. This
+means that if you want to add methods to a particular perl type
+(i.e. - monkeypatch), then you must do this:
-First, a warning.
+ sub Moose::Autobox::SCALAR::bar { 42 }
-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.
+instead of this:
-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.
+ sub SCALAR::bar { 42 }
-Also, as this is so experimental, it's API should not be considered
-to be stable. It could very well change in radical ways.
+as you would with vanilla autobox.
-=head1 DESCRIPTION
+=head1 METHODS
-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.
+=over 4
-=head2 A quick word about autobox
+=item B<mixin_additional_role ($type, $role)>
-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.
+This will mixin an additonal C<$role> into a certain C<$type>. The
+types can be SCALAR, ARRAY, HASH or CODE.
-=head2 Is this for real? or just play?
+This can be used to add additional methods to the types, see the
+F<examples/units/> directory for some examples.
-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 |
- +------------------------+-------------------------------+
- | Item | |
- | Undef | |
- | Defined | |
- | Scalar* <-|- String, Number <--+ |
- | Ref | |-- Value |
- | Array* <-|- List <------------+ |
- | Hash* | |
- | Code* | |
- | | |
- +------------------------+-------------------------------+
-
- * indicates actual autoboxed types
+=back
=head1 TODO
=back
-=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 BUGS
All complex software has bugs lurking in it, and this module is no
Stevan Little E<lt>stevan@iinteractive.comE<gt>
-=head1 COPYRIGHT AND LICENSE
+B<with contributions from:>
-Copyright 2006 by Infinity Interactive, Inc.
+Anders (Debolaz) Nor Berle
-L<http://www.iinteractive.com>
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-package Moose::Autobox;
-
-use strict;
-use warnings;
-
-use Carp qw(confess);
-use Scalar::Util ();
-
-our $VERSION = '0.02';
-
-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__
-
-=pod
-
-=head1 NAME
-
-Moose::Autobox - Autoboxed for her pleasure
-
-=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<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.
-
-Also, as this is so experimental, it's API should not be considered
-to be stable. It could very well change in radical ways.
+Matt (mst) Trout
-=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 |
- +------------------------+-------------------------------+
- | Item | |
- | Undef | |
- | Defined | |
- | Scalar* <-|- String, Number <--+ |
- | Ref | |-- Value |
- | Array* <-|- List <------------+ |
- | Hash* | |
- | Code* | |
- | | |
- +------------------------+-------------------------------+
-
- * indicates actual autoboxed types
-
-=head1 TODO
-
-=over 4
-
-=item More docs
-
-=item More tests
-
-=back
-
-=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 BUGS
-
-All complex software has bugs lurking in it, and this module is no
-exception. If you find a bug please either email me, or add the bug
-to cpan-RT.
-
-=head1 AUTHOR
-
-Stevan Little E<lt>stevan@iinteractive.comE<gt>
+renormalist
=head1 COPYRIGHT AND LICENSE
-Copyright 2006 by Infinity Interactive, Inc.
+Copyright 2006-2008 by Infinity Interactive, Inc.
L<http://www.iinteractive.com>