From: Jesse Luehrs Date: Thu, 20 Aug 2009 04:15:02 +0000 (-0500) Subject: remove head, tail, and last as Array helpers X-Git-Tag: 0.89_02~54 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9a14bd2969038591aa0cc510fbac6e46e6177f59;p=gitmo%2FMoose.git remove head, tail, and last as Array helpers --- diff --git a/lib/Moose/Manual/Delta.pod b/lib/Moose/Manual/Delta.pod index 39e7584..abcbd8b 100644 --- a/lib/Moose/Manual/Delta.pod +++ b/lib/Moose/Manual/Delta.pod @@ -46,12 +46,13 @@ Previously, the C method provided by Arrays and Hashes returned true if the attribute was B empty (no elements). Now it returns true if the attribute B empty. It was also renamed to C, to reflect this. -=item C was renamed to C, and C was renamed to C +=item C was renamed to C, and C and C were removed L refers to the functionality that we used to provide under C as L, so that will likely be more familiar (and will -fit in better if we decide to add more List::Util functions). C is an -obvious choice to replace what used to be called C. +fit in better if we decide to add more List::Util functions). C and +C were removed, since their functionality is easily duplicated with +curries of C. =item Helpers that take a coderef of one argument now use C<$_> diff --git a/lib/Moose/Meta/Attribute/Native/MethodProvider/Array.pm b/lib/Moose/Meta/Attribute/Native/MethodProvider/Array.pm index 4181fc8..ebc887d 100644 --- a/lib/Moose/Meta/Attribute/Native/MethodProvider/Array.pm +++ b/lib/Moose/Meta/Attribute/Native/MethodProvider/Array.pm @@ -86,28 +86,6 @@ sub join : method { }; } -sub head : method { - my ( $attr, $reader, $writer ) = @_; - return sub { - $reader->( $_[0] )->[0]; - }; -} - -sub tail : method { - my ( $attr, $reader, $writer ) = @_; - return sub { - my $arr = $reader->( $_[0] ); - return @{ $arr }[1..$#{ $arr }]; - }; -} - -sub last : method { - my ( $attr, $reader, $writer ) = @_; - return sub { - $reader->( $_[0] )->[-1]; - }; -} - sub push : method { my ( $attr, $reader, $writer ) = @_; diff --git a/lib/Moose/Meta/Attribute/Native/Trait/Array.pm b/lib/Moose/Meta/Attribute/Native/Trait/Array.pm index 2258d10..139fccf 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/Array.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/Array.pm @@ -46,9 +46,6 @@ Moose::Meta::Attribute::Native::Trait::Array map_options => 'map', filter_options => 'grep', find_option => 'first', - first_option => 'head', - all_but_first_option => 'tail', - last_option => 'last', get_option => 'get', join_options => 'join', count_options => 'count', @@ -190,27 +187,6 @@ Inserts a new element into the array at the given index. Empties the entire array, like C<@array = ()>. -=item B - -Returns the first element of the array. - - my $first = $stuff->first_option; - print "$first\n"; # prints "foo" - -=item B - -Returns all elements of the array after the first. - - my @tail = $stuff->all_but_first_option; - print join(', ', @tail), "\n"; # prints "bar, baz, boo" - -=item B - -Returns the last element of the array. - - my $last = $stuff->last_option; - print "$last\n"; # prints "boo" - =item B This method provides a get/set accessor for the array, based on array indexes. diff --git a/t/070_native_traits/205_trait_list.t b/t/070_native_traits/205_trait_list.t index 8f0be38..f6fe862 100644 --- a/t/070_native_traits/205_trait_list.t +++ b/t/070_native_traits/205_trait_list.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 34; +use Test::More tests => 31; use Test::Exception; use Test::Moose 'does_ok'; @@ -29,9 +29,6 @@ my $up; 'options' => 'elements', 'join_options' => 'join', 'get_option_at' => 'get', - 'get_first_option' => 'head', - 'all_but_first_option' => 'tail', - 'get_last_option' => 'last', 'sorted_options' => 'sort', 'less_than_five' => [ grep => [ $less = sub { $_ < 5 } ] ], 'up_by_one' => [ map => [ $up = sub { $_ + 1 } ] ], @@ -63,9 +60,6 @@ is_deeply( $stuff->_options, [ 1 .. 10 ], '... got options' ); ok( !$stuff->has_no_options, '... we have options' ); is( $stuff->num_options, 10, '... got 2 options' ); cmp_ok( $stuff->get_option_at(0), '==', 1, '... get option 0' ); -cmp_ok( $stuff->get_first_option, '==', 1, '... get head' ); -is_deeply( [ $stuff->all_but_first_option ], [ 2 .. 10 ], '... get tail' ); -cmp_ok( $stuff->get_last_option, '==', 10, '... get last' ); is_deeply( [ $stuff->filter_options( sub { $_ % 2 == 0 } ) ], @@ -126,9 +120,6 @@ is_deeply( 'options' => 'elements', 'join_options' => 'join', 'get_option_at' => 'get', - 'get_first_option' => 'head', - 'all_but_first_option' => 'tail', - 'get_last_option' => 'last', 'sorted_options' => 'sort', 'less_than_five' => [ grep => [$less] ], 'up_by_one' => [ map => [$up] ],