From bd5b0301a6685f02610ce322c0c4bf2d684d0484 Mon Sep 17 00:00:00 2001 From: Felix Ostmann Date: Wed, 12 May 2021 23:11:27 +0200 Subject: [PATCH] saving __SUB__ in a variable for later use --- lib/Mojolicious/Guides/Cookbook.pod | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Mojolicious/Guides/Cookbook.pod b/lib/Mojolicious/Guides/Cookbook.pod index 06880db74c..f30216b865 100644 --- a/lib/Mojolicious/Guides/Cookbook.pod +++ b/lib/Mojolicious/Guides/Cookbook.pod @@ -1413,12 +1413,15 @@ to process requests in smaller batches. # Stop if there are no more URLs return unless my $url = shift @urls; + # Save __SUB__ for later use in another callback + my $fetch = __SUB__; + # Fetch the next title $ua->get($url => sub ($ua, $tx) { say "$url: ", $tx->result->dom->at('title')->text; # Next request - __SUB__->(); + $fetch->(); $promise->resolve if --$count == 0; }); $count++;