Skip to content

Commit

Permalink
better AUTOLOAD examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 13, 2014
1 parent 550e775 commit 3ae409b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/Mojo/Collection.pm
Expand Up @@ -338,8 +338,10 @@ In addition to the L</"METHODS"> above, you can also call methods provided by
all elements in the collection directly and create a new collection from the
results, similar to L</"pluck">.
push @$collection, Mojo::DOM->new("<div><h1>$_</h1></div>") for 1 .. 9;
say $collection->find('h1')->type('h2')->prepend_content('Test ')->root;
# "<h2>Test1</h2><h2>Test2</h2>"
my $collection = Mojo::Collection->new;
push @$collection, Mojo::DOM->new("<h1>$_</h1>") for 1 .. 2;
$collection->find('h1')->type('h2')->prepend_content('Test ')->first->root;
=head1 OPERATORS
Expand Down
11 changes: 8 additions & 3 deletions lib/Mojo/DOM.pm
Expand Up @@ -913,9 +913,14 @@ automatically available as object methods, which return a L<Mojo::DOM> or
L<Mojo::Collection> object, depending on number of children. For more power
and consistent results you can also use L</"children">.
say $dom->p->text;
say $dom->div->[23]->text;
say $dom->div->text;
# "Test"
$dom->parse('<p>Test</p>')->p->text;
# "B"
$dom->parse('<div>A</div><div>B</div>')->div->[2]->text;
# "A"
$dom->parse('<div>A</div>')->div->text;
=head1 OPERATORS
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -597,11 +597,13 @@ variations.
In addition to the L</"ATTRIBUTES"> and L</"METHODS"> above you can also call
shortcuts provided by L</"root"> on L<Mojolicious::Routes::Route> objects.
# Add a "firefox" shortcut
$r->root->add_shortcut(firefox => sub {
my ($r, $path) = @_;
$r->get($path, agent => qr/Firefox/);
});
# Use "firefox" shortcut to generate routes
$r->firefox('/welcome')->to('firefox#welcome');
$r->firefox('/bye')->to('firefox#bye');
Expand Down

0 comments on commit 3ae409b

Please sign in to comment.