Revision history for Perl extension Moose::Autobox
+ - add first and last to Scalar and Array (t0m)
+
0.10
- add each, each_key, each_value to Indexed (array and hash) (rjbs)
- add split, words, lines to String (Sartak)
[ CORE::sort { $sub->($a, $b) } @$array ];
}
+sub first {
+ $_[0]->[0];
+}
+
+sub last {
+ $_[0]->[$#{$_[0]}];
+}
+
## ::Indexed implementation
sub at {
=item B<flatten_deep ($depth)>
-=item B<each_n_values ($n, $callback)>
+=item B<first>
+
+=item B<last>
=back
=item B<each_value>
+=item B<each_n_values ($n, $callback)>
+
=back
=head2 List implementation
'Moose::Autobox::Number';
sub flatten { $_[0] }
+sub first { $_[0] }
+sub last { $_[0] }
sub print { CORE::print $_[0] }
sub say { CORE::print $_[0], "\n" }
1;
=back
+=item B<first>
+
+As per flatten.
+
+=item B<last>
+
+As per flatten.
+
=head1 BUGS
All complex software has bugs lurking in it, and this module is no
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+require_ok('Moose::Autobox');
+
+use Moose::Autobox;
+
+my $string = 'foo';
+my $list = ['foo', 'bar'];
+
+is $string->first, 'foo';
+is $string->last, 'foo';
+
+is $list->first, 'foo';
+is $list->last, 'bar';