As I mention in my comment, Mojo::IOLoop doesn't concern with parallelism but with event loops. This means that operations which may take a long time may be started and then continued only once complete without blocking the other processes. In your example both the call to Mongo and the download are these types of long-running processes which one may want to put in the event loop. Mojolicious::UserAgent is non-blocking when used with a callback (the action called once the operation is complete). To do the same with Mongo you will need to be sure your Mongo library can be used in a non-blocking fashion.
I have mocked up a little example which ignores the Mongo part (exercise for the reader) and uses the UserAgent in a non-blocking fashion.
#!/usr/bin/env perl
use Mojolicious::Lite;
helper download => sub {
my ($c, $url, $target) = @_;
my $ua = $c->app->ua->max_redirects(5);
say "Starting new download ($url) ...";
$ua->get( $url, sub {
my ($ua, $tx) = @_;
say "Finished download ($url) ...";
$tx->res->content->asset->move_to($target);
say "File saved ($url --> $target)";
$c->render( text => "File saved ($url --> $target)" );
});
};
any [qw/ get post /] => '/:action/:objid' => sub {
my $self = shift;
$self->render_later; # prevent auto-render
#Parsing objectid
my $objectid = $self->param('objid');
#verify url here ...
# example url
my $url = 'http://www.google.com';
$self->download($url,"final_name.xml");
};
app->start;