Skip to content

Commit bd5b030

Browse files
committed
saving __SUB__ in a variable for later use
1 parent e0afa09 commit bd5b030

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/Mojolicious/Guides/Cookbook.pod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,12 +1413,15 @@ to process requests in smaller batches.
14131413
# Stop if there are no more URLs
14141414
return unless my $url = shift @urls;
14151415

1416+
# Save __SUB__ for later use in another callback
1417+
my $fetch = __SUB__;
1418+
14161419
# Fetch the next title
14171420
$ua->get($url => sub ($ua, $tx) {
14181421
say "$url: ", $tx->result->dom->at('title')->text;
14191422

14201423
# Next request
1421-
__SUB__->();
1424+
$fetch->();
14221425
$promise->resolve if --$count == 0;
14231426
});
14241427
$count++;

0 commit comments

Comments
 (0)