Acme-CPANModulesBundle-Import-MojoliciousAdvent-2018
view release on metacpan or search on metacpan
devdata/https_mojolicious.io_blog_2018_12_01_welcome-mojoconf-recap_ view on Meta::CPAN
<p>On a personal note, I especially enjoyed this trip because I was able to take a few extra days to visit the West of Norway, home to the iconic fjords.
I visited Bergen and several of its Perlers before taking a fjord tour by boat and train.
It would have been the perfect trip if my bag hadn't decided that it wanted to stay an extra few days in Iceland where I'd had a delayed stop-over.</p>
<p>Still I had an amazing times and saw once in a lifetime sights!
Thanks to Christopher and Jonis and all the people whoe were my companions for the trip!</p>
<h2>Nordic Perl Workshop and MojoConf</h2>
<p>The Oslo Perl Mongers know how to throw Perl events!
This year I actually was there twice, having been once before for the <a href="http://blogs.perl.org/users/joel_berger/2018/04/perl-toolchain-summit-2018.html">Perl Toolchain Summit</a>.</p>
<p>Nordic Perl Workshop is, as its name implies, a regional workshop for Perl enthusiats to gather and talk Perl together.
This year however, it was co-branded as MojoConf 2018; the previous MojoConf was also held in Oslo in 2014.</p>
<p>There were lots of great talks, both on Mojolicious and on Perl in general.
You can <a href="https://www.youtube.com/playlist?list=PL3IiTqgYQ8s0DeRIHW6fXJ4w-BJIMHuDS">see them all</a> on the <a href="https://www.youtube.com/channel/UCgk2wCZr5Rk-cewLTtQA_Fg">NPW Youtube Channel</a>.
For brevity, I'll just highlight a few here.</p>
<h3>Keynote</h3>
devdata/https_mojolicious.io_blog_2018_12_12_dancer-and-minion_ view on Meta::CPAN
}
sub get_invalid_queues( $self, @queues ) {
my %queue_map;
@queue_map{ @QUEUE_TYPES } = ();
my @invalid_queues = grep !exists $queue_map{ $_ }, @queues;
return @invalid_queues;
}
</code></pre>
<p>With that in place, it was easy for our <code>queue_job()</code> method to throw an error if the developer tried to add a job to an invalid queue:</p>
<pre><code>sub queue_job( $self, $args ) {
my $job_name = $args->{ name } or die "queue_job(): must define job name!";
my $guid = $args->{ guid } or die "queue_job(): must have GUID to process!";
my $title = $args->{ title } // $job_name;
my $queue = $args->{ queue } // 'default';
my $job_args = $args->{ job_args };
die "queue_job(): Invalid job queue '$queue' specified" if $self->has_invalid_queues( $queue );
devdata/https_mojolicious.io_blog_2018_12_23_mojolicious-and-angular_ view on Meta::CPAN
title => 'Higher Order Promises',
day => 3,
author => 'brain d foy',
},
],
status => 200,
);
});
</code></pre>
<p>As a sidenote, you may have to allow <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">Cross Origin Resource Sharing (CORS)</a> if the Angular app throws an error while accessing the mojo API endpoint.
In that case you may want to make use of the <a href="https://mojolicious.org/perldoc/Mojolicious/#before_dispatch"><code>before_dispatch</code></a> app hook:</p>
<pre><code>$self->hook(before_dispatch => sub {
my $c = shift;
$c->res->headers->header('Access-Control-Allow-Origin' => '*');
});
</code></pre>
<p>But please note, in a real-world application <code>*</code> is defeating the security feature.</p>
devdata/https_mojolicious.io_blog_2018_12_24_async-await-the-mojo-way_ view on Meta::CPAN
Everything in it is applicable even as this article takes it one step further below ...</em></p>
<h2>Async/Await</h2>
<p>What we really wish we could tell the Perl interpreter to do is</p>
<ul>
<li>suspend execution until this promise resolves or is rejected</li>
<li>then move on to handle tasks</li>
<li>when it eventually does resolve or reject</li>
<li>then resume processing right here or throw an exception</li>
</ul>
<p>It is a big ask, but if you could say that, you'd basically get linearity back.
Promises give us the control we'd need for such a mechanism, but until now we in Perl-land lack the ability to suspend and resume the interpreter.
Indeed, some languages already have this mechanism and the result is called the Async/Await pattern.
With a little added magic, howver, we can do just that.</p>
<p>That was a lot of introduction, but now I'm finally ready to introduce <a href="https://metacpan.org/pod/Mojo::AsyncAwait">Mojo::AsyncAwait</a>!</p>
<pre><code>use Mojo::AsyncAwait;
( run in 0.417 second using v1.01-cache-2.11-cpan-496ff517765 )