From: Stevan Little Date: Fri, 9 Jun 2006 12:31:10 +0000 (+0000) Subject: foo X-Git-Tag: 0_02~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=31d40d7362f4154746428525561af751208b0805;p=gitmo%2FMoose-Autobox.git foo --- diff --git a/lib/Moose/Autobox.pm b/lib/Moose/Autobox.pm index 967778e..599e3a0 100644 --- a/lib/Moose/Autobox.pm +++ b/lib/Moose/Autobox.pm @@ -4,7 +4,7 @@ package Moose::Autobox; use strict; use warnings; -use Moose qw(confess); +use Carp qw(confess); use Scalar::Util (); our $VERSION = '0.01'; @@ -12,20 +12,39 @@ 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'; +*does = \&Moose::Object::does; + package CODE; +use base 'Moose::Autobox'; use Moose; -with 'Moose::Autobox::Code'; +with 'Moose::Autobox::Code'; + +*does = \&Moose::Object::does; + # |; # confess 'Could not create autobox packages because - ' . $@ if $@; #} @@ -44,26 +63,33 @@ Moose::Autobox - autoboxed for her pleasure use Moose::Autobox; use autobox; - - print "Squares: " . [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', '); + + 'Print squares from 1 to 10'->print; + [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ')->print; =head1 DESCRIPTION =head1 ROLES - Item - Undef - Defined - Value - Scalar* - Ref - List - Array* - Hash* - Code* - + 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 Values. + + - 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 diff --git a/lib/Moose/Autobox/Array.pm b/lib/Moose/Autobox/Array.pm index a33c1b5..6d4c1e8 100644 --- a/lib/Moose/Autobox/Array.pm +++ b/lib/Moose/Autobox/Array.pm @@ -5,7 +5,8 @@ use autobox; our $VERSION = '0.01'; with 'Moose::Autobox::Ref', - 'Moose::Autobox::List'; + 'Moose::Autobox::List', + 'Moose::Autobox::Indexed'; ## Array Interface @@ -46,6 +47,16 @@ sub sprintf { CORE::sprintf $_[1], @{$_[0]} } sub head { $_[0]->[0] } sub tail { [ @{$_[0]}[ 1 .. $#{$_[0]} ] ] } +sub at { + my ($array, $index) = @_; + $array->[$index]; +} + +sub put { + my ($array, $index, $value) = @_; + $array->[$index] = $value; +} + sub length { my ($array) = @_; CORE::scalar @$array; @@ -105,3 +116,41 @@ sub kv { } 1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Array - the Array role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + + print "Squares: " . [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', '); + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Code.pm b/lib/Moose/Autobox/Code.pm index 72a529f..1d6b3f3 100644 --- a/lib/Moose/Autobox/Code.pm +++ b/lib/Moose/Autobox/Code.pm @@ -32,4 +32,46 @@ sub conjoin { return sub { $f->(@_) && $f2->(@_) } } -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Code - the Code role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + + my $adder = sub { $_[0] + $_[1] }; + + $add_2 = $adder->curry(2); + + $add_2->(2); # returns 4 + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Defined.pm b/lib/Moose/Autobox/Defined.pm index a71010a..ecb06cc 100644 --- a/lib/Moose/Autobox/Defined.pm +++ b/lib/Moose/Autobox/Defined.pm @@ -7,4 +7,40 @@ with 'Moose::Autobox::Item'; sub defined { 1 } -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Defined - the Defined role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Hash.pm b/lib/Moose/Autobox/Hash.pm index 50d77dc..997440d 100644 --- a/lib/Moose/Autobox/Hash.pm +++ b/lib/Moose/Autobox/Hash.pm @@ -6,6 +6,8 @@ our $VERSION = '0.01'; with 'Moose::Autobox::Ref', 'Moose::Autobox::Indexed'; + + sub delete { my ($hash, $key) = @_; CORE::delete $hash->{$key}; @@ -13,6 +15,16 @@ sub delete { # ::Indexed implementation +sub at { + my ($hash, $index) = @_; + $hash->{$index}; +} + +sub put { + my ($hash, $index, $value) = @_; + $hash->{$index} = $value; +} + sub exists { my ($hash, $key) = @_; CORE::exists $hash->{$key}; @@ -33,4 +45,42 @@ sub kv { [ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ]; } -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Hash - the Hash role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + + { one => 1, two => 2 }->keys->join(', ')->print; # prints 'one, two' + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Indexed.pm b/lib/Moose/Autobox/Indexed.pm index 9b923cf..3f03fec 100644 --- a/lib/Moose/Autobox/Indexed.pm +++ b/lib/Moose/Autobox/Indexed.pm @@ -3,6 +3,49 @@ use Moose::Role 'requires'; our $VERSION = '0.01'; -requires qw/exists keys values kv/; +requires qw/ + at + put + exists + keys + values + kv +/; -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Indexed - the Indexed role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Item.pm b/lib/Moose/Autobox/Item.pm index 61cd996..00b40b6 100644 --- a/lib/Moose/Autobox/Item.pm +++ b/lib/Moose/Autobox/Item.pm @@ -5,4 +5,40 @@ our $VERSION = '0.01'; requires 'defined'; -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Item - the Item role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/List.pm b/lib/Moose/Autobox/List.pm index 4431dc1..2c45a4f 100644 --- a/lib/Moose/Autobox/List.pm +++ b/lib/Moose/Autobox/List.pm @@ -5,14 +5,16 @@ use autobox; our $VERSION = '0.01'; -with 'Moose::Autobox::Indexed'; +with 'Moose::Autobox::Value'; requires qw/ - head + head tail length join - grep map sort + grep + map + sort reverse /; @@ -31,8 +33,44 @@ sub zip { : $array) ->keys ->map(sub { - [ $array->[$_], $other->[$_] ] + [ $array->at($_), $other->at($_) ] }); } -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::List - the List role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Number.pm b/lib/Moose/Autobox/Number.pm new file mode 100644 index 0000000..e45d14d --- /dev/null +++ b/lib/Moose/Autobox/Number.pm @@ -0,0 +1,44 @@ +package Moose::Autobox::Number; +use Moose::Role; + +our $VERSION = '0.01'; + +with 'Moose::Autobox::Value'; + +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Number - the Number role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Ref.pm b/lib/Moose/Autobox/Ref.pm index a5221d6..f4a2562 100644 --- a/lib/Moose/Autobox/Ref.pm +++ b/lib/Moose/Autobox/Ref.pm @@ -5,6 +5,40 @@ our $VERSION = '0.01'; with 'Moose::Autobox::Defined'; +1; +__END__ -1; \ No newline at end of file +=pod + +=head1 NAME + +Moose::Autobox::Ref - the Ref role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Scalar.pm b/lib/Moose/Autobox/Scalar.pm index dc8a12d..ca80a79 100644 --- a/lib/Moose/Autobox/Scalar.pm +++ b/lib/Moose/Autobox/Scalar.pm @@ -3,11 +3,47 @@ use Moose::Role 'with'; our $VERSION = '0.01'; -with 'Moose::Autobox::Value', - 'Moose::Autobox::String'; +with 'Moose::Autobox::String', + 'Moose::Autobox::Number'; # ::Value requirement -sub print { CORE::print $_[0] } +sub print { CORE::print $_[0] } -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Scalar - the Scalar role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/String.pm b/lib/Moose/Autobox/String.pm index 1a57f4a..6e224a4 100644 --- a/lib/Moose/Autobox/String.pm +++ b/lib/Moose/Autobox/String.pm @@ -3,6 +3,8 @@ use Moose::Role; our $VERSION = '0.01'; +with 'Moose::Autobox::Value'; + # perl built-ins sub lc { CORE::lc $_[0] } @@ -18,4 +20,42 @@ sub index { CORE::index $_[0], $_[1], (defined $_[2] ? $_[2] : ()) } # FIXME: this is not working #sub rindex { CORE::rindex $_[0], $_[1], (defined $_[2] ? $_[2] : ()) } -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::String - the String role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + + "Hello World"->uc; # HELLO WORLD + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Undef.pm b/lib/Moose/Autobox/Undef.pm index c6af495..3876644 100644 --- a/lib/Moose/Autobox/Undef.pm +++ b/lib/Moose/Autobox/Undef.pm @@ -7,4 +7,40 @@ with 'Moose::Autobox::Item'; sub defined { 0 } -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Undef - the Undef role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/lib/Moose/Autobox/Value.pm b/lib/Moose/Autobox/Value.pm index 4121148..e3c88ed 100644 --- a/lib/Moose/Autobox/Value.pm +++ b/lib/Moose/Autobox/Value.pm @@ -13,4 +13,44 @@ sub do { $block->($self); } -1; \ No newline at end of file +1; +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Value - the Value role + +=head1 SYNOPOSIS + + use Moose::Autobox; + use autobox; + + 5->print; # prints 5 + + # excute a sub on the value + 10->do(sub { $_ + 15 })->print; # prints 25 + +=head1 DESCRIPTION + +=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 Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/t/000_load.t b/t/000_load.t index 32c9d47..d08d8ad 100644 --- a/t/000_load.t +++ b/t/000_load.t @@ -3,8 +3,22 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 14; BEGIN { use_ok('Moose::Autobox'); + + use_ok('Moose::Autobox::Array'); + use_ok('Moose::Autobox::Code'); + use_ok('Moose::Autobox::Defined'); + use_ok('Moose::Autobox::Hash'); + use_ok('Moose::Autobox::Indexed'); + use_ok('Moose::Autobox::Item'); + use_ok('Moose::Autobox::List'); + use_ok('Moose::Autobox::Number'); + use_ok('Moose::Autobox::Ref'); + use_ok('Moose::Autobox::Scalar'); + use_ok('Moose::Autobox::String'); + use_ok('Moose::Autobox::Undef'); + use_ok('Moose::Autobox::Value'); } \ No newline at end of file