use strict;
use warnings;
-use Moose qw(confess);
+use Carp qw(confess);
use Scalar::Util ();
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 $@;
#}
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
our $VERSION = '0.01';
with 'Moose::Autobox::Ref',
- 'Moose::Autobox::List';
+ 'Moose::Autobox::List',
+ 'Moose::Autobox::Indexed';
## Array Interface
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;
}
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 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
\ No newline at end of file
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 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
\ No newline at end of file
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 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
\ No newline at end of file
with 'Moose::Autobox::Ref',
'Moose::Autobox::Indexed';
+
+
sub delete {
my ($hash, $key) = @_;
CORE::delete $hash->{$key};
# ::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};
[ 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 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
\ No newline at end of file
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 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
\ No newline at end of file
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 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
\ No newline at end of file
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
/;
: $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 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
\ No newline at end of file
--- /dev/null
+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 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
\ No newline at end of file
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 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
\ No newline at end of file
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 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
\ No newline at end of file
our $VERSION = '0.01';
+with 'Moose::Autobox::Value';
+
# perl built-ins
sub lc { CORE::lc $_[0] }
# 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 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
\ No newline at end of file
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 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
\ No newline at end of file
$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 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
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