Skip to content

Commit

Permalink
explain how $a and $b are used
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 30, 2016
1 parent 4546d77 commit cc2c45a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

6.58 2016-03-28
6.58 2016-03-30
- Added fork policy to Mojolicious::Guides::Contributing.

6.57 2016-03-23
Expand Down
12 changes: 8 additions & 4 deletions lib/Mojo/Collection.pm
Expand Up @@ -284,8 +284,11 @@ Construct a new array-based L<Mojo::Collection> object.
my $result = $collection->reduce(sub {...});
my $result = $collection->reduce(sub {...}, $initial);
Reduce elements in collection with callback, the first element will be used as
initial value if none has been provided.
Reduce elements in collection with a callback and return its final result,
setting C<$a> and C<$b> each time the callback is executed. The first time C<$a>
will be set to an optional initial value or the first element in the collection.
And from then on C<$a> will be set to the return value of the callback, while
C<$b> will always be set to the next element in the collection.
# Calculate the sum of all values
my $sum = $collection->reduce(sub { $a + $b });
Expand Down Expand Up @@ -325,8 +328,9 @@ Number of elements in collection.
my $new = $collection->sort;
my $new = $collection->sort(sub {...});
Sort elements based on return value of callback and create a new collection
from the results.
Sort elements based on return value of a callback and create a new collection
from the results, setting C<$a> and C<$b> to the elements being compared, each
time the callback is executed.
# Sort values case-insensitive
my $case_insensitive = $collection->sort(sub { uc($a) cmp uc($b) });
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -441,7 +441,8 @@ templates.
Reply with a static file using L<Mojolicious/"static">, usually from the
C<public> directories or C<DATA> sections of your application. Note that this
helper does not protect from traversing to parent directories.
helper uses a relative path, but does not protect from traversing to parent
directories.
# Serve file with a custom content type
$c->res->headers->content_type('application/myapp');
Expand Down
7 changes: 4 additions & 3 deletions lib/Mojolicious/Static.pm
Expand Up @@ -219,8 +219,8 @@ Serve static file for L<Mojolicious::Controller> object.
Build L<Mojo::Asset::File> or L<Mojo::Asset::Memory> object for a file,
relative to L</"paths"> or from L</"classes">, or return C<undef> if it doesn't
exist. Note that this method does not protect from traversing to parent
directories.
exist. Note that this method uses a relative path, but does not protect from
traversing to parent directories.
my $content = $static->file('foo/bar.html')->slurp;
Expand Down Expand Up @@ -256,7 +256,8 @@ Add C<Last-Modified> header before comparing.
my $bool = $static->serve(Mojolicious::Controller->new, '../lib/MyApp.pm');
Serve a specific file, relative to L</"paths"> or from L</"classes">. Note that
this method does not protect from traversing to parent directories.
this method uses a relative path, but does not protect from traversing to parent
directories.
=head2 serve_asset
Expand Down

0 comments on commit cc2c45a

Please sign in to comment.