Skip to content

Commit

Permalink
removed hash reference support from pluck again
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 5, 2014
1 parent f132af6 commit c36588c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Changes
@@ -1,7 +1,5 @@

5.48 2014-10-05
- Improved pluck method in Mojo::Collection to be able to extract values
from hash references.

5.47 2014-09-28
- Improved url_for performance.
Expand Down
9 changes: 3 additions & 6 deletions lib/Mojo/Collection.pm
Expand Up @@ -70,8 +70,7 @@ sub new {

sub pluck {
my ($self, $method, @args) = @_;
return $self->new(
map { ref $_ eq 'HASH' ? $_->{$method} : $_->$method(@args) } @$self);
return $self->new(map { $_->$method(@args) } @$self);
}

sub reduce {
Expand Down Expand Up @@ -263,15 +262,13 @@ Construct a new array-based L<Mojo::Collection> object.
=head2 pluck
my $new = $collection->pluck($key);
my $new = $collection->pluck($method);
my $new = $collection->pluck($method, @args);
Extract value from hash reference or call method on each element in collection
and create a new collection from the results.
Call method on each element in collection and create a new collection from the
results.
# Equal to but more convenient than
my $new = $collection->map(sub { $_->{$key} });
my $new = $collection->map(sub { $_->$method(@args) });
=head2 reduce
Expand Down
2 changes: 0 additions & 2 deletions t/mojo/collection.t
Expand Up @@ -144,8 +144,6 @@ is_deeply [$collection->slice(6, 1, 4)->each], [7, 2, 5], 'right result';
is_deeply [$collection->slice(6 .. 9)->each], [7, 10, 9, 8], 'right result';

# pluck
is c({foo => 'bar'}, {foo => 'baz'})->pluck('foo')->join, 'barbaz',
'right result';
$collection = c(c(1, 2, 3), c(4, 5, 6), c(7, 8, 9));
is $collection->pluck('reverse'), "3\n2\n1\n6\n5\n4\n9\n8\n7", 'right result';
is $collection->pluck(join => '-'), "1-2-3\n4-5-6\n7-8-9", 'right result';
Expand Down

0 comments on commit c36588c

Please sign in to comment.