Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better examples for method arguments
  • Loading branch information
kraih committed Mar 21, 2016
1 parent 25226b4 commit eb79af2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

6.57 2016-03-20
6.57 2016-03-21
- Fixed a few validation bugs in Mojolicious::Validator::Validation.
(Mikey, sri)

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Base.pm
Expand Up @@ -222,8 +222,8 @@ pass it either a hash or a hash reference with attribute values.
=head2 tap
$object = $object->tap(sub {...});
$object = $object->tap($method);
$object = $object->tap($method, @args);
$object = $object->tap('some_method');
$object = $object->tap('some_method', @args);
Tap into a method chain to perform operations on an object within the chain
(also known as a K combinator or Kestrel). The object will be the first argument
Expand All @@ -233,7 +233,7 @@ be the return value. In this way, arbitrary code can be used within (i.e.,
spliced or tapped into) a chained set of object method calls.
# Longer version
$object = $object->tap(sub { $_->$method(@args) });
$object = $object->tap(sub { $_->some_method(@args) });
# Inject side effects into a method chain
$object->foo('A')->tap(sub { say $_->foo })->foo('B');
Expand Down
24 changes: 12 additions & 12 deletions lib/Mojo/Collection.pm
Expand Up @@ -192,16 +192,16 @@ to the callback, and is also available as C<$_>.
my $first = $collection->first;
my $first = $collection->first(qr/foo/);
my $first = $collection->first(sub {...});
my $first = $collection->first($method);
my $first = $collection->first($method, @args);
my $first = $collection->first('some_method');
my $first = $collection->first('some_method', @args);
Evaluate regular expression/callback for, or call method on, each element in
collection and return the first one that matched the regular expression, or for
which the callback/method returned true. The element will be the first argument
passed to the callback, and is also available as C<$_>.
# Longer version
my $first = $collection->first(sub { $_->$method(@args) });
my $first = $collection->first(sub { $_->some_method(@args) });
# Find first value that contains the word "mojo"
my $interesting = $collection->first(qr/mojo/i);
Expand All @@ -223,8 +223,8 @@ all elements.
my $new = $collection->grep(qr/foo/);
my $new = $collection->grep(sub {...});
my $new = $collection->grep($method);
my $new = $collection->grep($method, @args);
my $new = $collection->grep('some_method');
my $new = $collection->grep('some_method', @args);
Evaluate regular expression/callback for, or call method on, each element in
collection and create a new collection with all elements that matched the
Expand All @@ -233,7 +233,7 @@ will be the first argument passed to the callback, and is also available as
C<$_>.
# Longer version
my $new = $collection->grep(sub { $_->$method(@args) });
my $new = $collection->grep(sub { $_->some_method(@args) });
# Find all values that contain the word "mojo"
my $interesting = $collection->grep(qr/mojo/i);
Expand All @@ -260,15 +260,15 @@ Return the last element in collection.
=head2 map
my $new = $collection->map(sub {...});
my $new = $collection->map($method);
my $new = $collection->map($method, @args);
my $new = $collection->map('some_method');
my $new = $collection->map('some_method', @args);
Evaluate callback for, or call method on, each element in collection and create
a new collection from the results. The element will be the first argument
passed to the callback, and is also available as C<$_>.
# Longer version
my $new = $collection->map(sub { $_->$method(@args) });
my $new = $collection->map(sub { $_->some_method(@args) });
# Append the word "mojo" to all values
my $mojoified = $collection->map(sub { $_ . 'mojo' });
Expand Down Expand Up @@ -347,15 +347,15 @@ Turn collection into array reference.
my $new = $collection->uniq;
my $new = $collection->uniq(sub {...});
my $new = $collection->uniq($method);
my $new = $collection->uniq($method, @args);
my $new = $collection->uniq('some_method');
my $new = $collection->uniq('some_method', @args);
Create a new collection without duplicate elements, using the string
representation of either the elements or the return value of the
callback/method.
# Longer version
my $new = $collection->uniq(sub { $_->$method(@args) });
my $new = $collection->uniq(sub { $_->some_method(@args) });
# "foo bar baz"
Mojo::Collection->new('foo', 'bar', 'bar', 'baz')->uniq->join(' ');
Expand Down

0 comments on commit eb79af2

Please sign in to comment.