1 package Moose::Autobox::Array;
2 use Moose::Role 'with';
7 with 'Moose::Autobox::Ref',
8 'Moose::Autobox::List',
9 'Moose::Autobox::Indexed';
19 my ($array, @rest) = @_;
20 CORE::push @$array, @rest;
25 my ($array, @rest) = @_;
26 CORE::unshift @$array, @rest;
31 my ($array, $index) = @_;
32 CORE::delete $array->[$index];
41 # sprintf args need to be reversed,
42 # because the invocant is the array
43 sub sprintf { CORE::sprintf $_[1], @{$_[0]} }
45 ## ::List interface implementation
47 sub head { $_[0]->[0] }
48 sub tail { [ @{$_[0]}[ 1 .. $#{$_[0]} ] ] }
56 my ($array, $sub) = @_;
57 [ CORE::grep { $sub->($_) } @$array ];
61 my ($array, $sub) = @_;
62 [ CORE::map { $sub->($_) } @$array ];
66 my ($array, $sep) = @_;
68 CORE::join $sep, @$array;
73 [ CORE::reverse @$array ];
77 my ($array, $sub) = @_;
78 $sub ||= sub { $a cmp $b };
79 [ CORE::sort { $sub->($a, $b) } @$array ];
82 ## ::Indexed implementation
85 my ($array, $index) = @_;
90 my ($array, $index, $value) = @_;
91 $array->[$index] = $value;
95 my ($array, $index) = @_;
96 CORE::exists $array->[$index];
111 $array->keys->map(sub { [ $_, $array->[$_] ] });
122 Moose::Autobox::Array - the Array role
129 print "Squares: " . [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
195 All complex software has bugs lurking in it, and this module is no
196 exception. If you find a bug please either email me, or add the bug
201 Stevan Little E<lt>stevan@iinteractive.comE<gt>
203 =head1 COPYRIGHT AND LICENSE
205 Copyright 2006 by Infinity Interactive, Inc.
207 L<http://www.iinteractive.com>
209 This library is free software; you can redistribute it and/or modify
210 it under the same terms as Perl itself.