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&#39;t decided that it wanted to stay an extra few days in Iceland where I&#39;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&#39;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-&gt;{ name     } or die &quot;queue_job(): must define job name!&quot;;
    my $guid     = $args-&gt;{ guid     } or die &quot;queue_job(): must have GUID to process!&quot;;
    my $title    = $args-&gt;{ title    } // $job_name;
    my $queue    = $args-&gt;{ queue    } // &#39;default&#39;;
    my $job_args = $args-&gt;{ job_args };

    die &quot;queue_job(): Invalid job queue &#39;$queue&#39; specified&quot; if $self-&gt;has_invalid_queues( $queue );

devdata/https_mojolicious.io_blog_2018_12_23_mojolicious-and-angular_  view on Meta::CPAN

                    title  =&gt; &#39;Higher Order Promises&#39;,
                    day    =&gt; 3,
                    author =&gt; &#39;brain d foy&#39;,
                },
            ],
        status =&gt; 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-&gt;hook(before_dispatch =&gt; sub {
    my $c = shift;
    $c-&gt;res-&gt;headers-&gt;header(&#39;Access-Control-Allow-Origin&#39; =&gt; &#39;*&#39;);
});
</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&#39;d basically get linearity back.
Promises give us the control we&#39;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&#39;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 )