Skip to content

Commit

Permalink
more collection examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 17, 2014
1 parent 8a0ab3d commit 5527061
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

5.70 2014-12-17
5.70 2014-12-18
- Improved Mojo::Template performance.
- Fixed error handling bugs in Mojo::IOLoop::Stream.
- Fixed a few limit bugs in Mojo::Message.
Expand Down
12 changes: 12 additions & 0 deletions lib/Mojo/Collection.pm
Expand Up @@ -189,6 +189,9 @@ L<Mojo::Collection> implements the following methods.
Create a new collection with all elements that are defined and not an empty
string.
# "0, 1, 2, 3"
Mojo::Collection->new(0, 1, undef, 2, '', 3)->compact->join(', ');
=head2 each
my @elements = $collection->each;
Expand Down Expand Up @@ -228,6 +231,9 @@ callback and is also available as C<$_>.
Flatten nested collections/arrays recursively and create a new collection with
all elements.
# "1, 2, 3, 4, 5, 6, 7"
Mojo::Collection->new(1, [2, [3, 4], 5, [6]], 7)->flatten->join(', ');
=head2 grep
my $new = $collection->grep(qr/foo/);
Expand Down Expand Up @@ -308,6 +314,9 @@ Create a new collection with all elements in reverse order.
Create a new collection with all selected elements.
# "B C E"
Mojo::Collection->new('A', 'B', 'C', 'D', 'E')->slice(1, 2, 4)->join(' ');
=head2 shuffle
my $new = $collection->shuffle;
Expand Down Expand Up @@ -349,6 +358,9 @@ Turn collection into array reference.
Create a new collection without duplicate elements.
# "foo bar baz"
Mojo::Collection->new('foo', 'bar', 'bar', 'baz')->uniq->join(' ');
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -98,9 +98,9 @@ sub _again { $_[0]->reactor->again($_[0]{timer}) if $_[0]{timer} }
sub _read {
my $self = shift;

if (defined(my $read = $self->{handle}->sysread(my $buffer, 131072, 0))) {
return $read == 0 ? $self->close : $self->emit(read => $buffer)->_again;
}
my $read = $self->{handle}->sysread(my $buffer, 131072, 0);
return $read == 0 ? $self->close : $self->emit(read => $buffer)->_again
if defined $read;

# Retry
return if $! == EAGAIN || $! == EINTR || $! == EWOULDBLOCK;
Expand Down

0 comments on commit 5527061

Please sign in to comment.