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]} ] ] }
51 my ($array, $index) = @_;
56 my ($array, $index, $value) = @_;
57 $array->[$index] = $value;
66 my ($array, $sub) = @_;
67 [ CORE::grep { $sub->($_) } @$array ];
71 my ($array, $sub) = @_;
72 [ CORE::map { $sub->($_) } @$array ];
76 my ($array, $sep) = @_;
78 CORE::join $sep, @$array;
83 [ CORE::reverse @$array ];
87 my ($array, $sub) = @_;
88 $sub ||= sub { $a cmp $b };
89 [ CORE::sort { $sub->($a, $b) } @$array ];
94 sub print { CORE::print @{$_[0]} }
96 ## ::Indexed implementation
99 my ($array, $index) = @_;
100 CORE::exists $array->[$index];
115 $array->keys->map(sub { [ $_, $array->[$_] ] });
126 Moose::Autobox::Array - the Array role
133 print "Squares: " . [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
139 All complex software has bugs lurking in it, and this module is no
140 exception. If you find a bug please either email me, or add the bug
145 Stevan Little E<lt>stevan@iinteractive.comE<gt>
147 =head1 COPYRIGHT AND LICENSE
149 Copyright 2006 by Infinity Interactive, Inc.
151 L<http://www.iinteractive.com>
153 This library is free software; you can redistribute it and/or modify
154 it under the same terms as Perl itself.