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


              <div class="post-thumb">
                <!-- theme suggests 1300x500 -->
                <img alt="View from fjord" src="/blog/2018/12/01/welcome-mojoconf-recap/banner.jpg">
              </div>

            <div class="post-content">

              <section id="section-1">
                  <p>Welcome to another year of the Mojolicious Advent Calendar!
2018 has been very good to Mojolicious and I could think of no better way to kick off this calendar than with a recap of the 2018 Nordic Perl Workshop and MojoConf held in Oslo, Norway.</p>

              </section>
              <section id="section-2">
                  <h2>Sidetrip to Western Norway</h2>

<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!

devdata/https_mojolicious.io_blog_2018_12_16_browser-diet_  view on Meta::CPAN

that hardly change.
I spent a well-caffeinated afternoon trying to do that with
Mojolicious.
I&#39;ve been &#39;round the houses, and <em>spoiler alert</em> I didn&#39;t find
the answer until the very end, kind of like your favourite Christmas
animated special with a small woodland creature narrating
&quot;The Gruffalo&#39;s HTTP header&quot;.</p>

<h1>A Children&#39;s Story</h1>

<p>Our beloved small woodland creature needed to display a web calendar
with forest events pulled from a database.
Perl could get the event data and package it as a JSON feed.
Mojolicious could prepare the webpages with the correct JSON feed for each user.
With some JavaScript libraries to display the web calendar,
all would be well in the forest.</p>

<p>Everything except the JavaScript libraries are lightweight.
And everyone knows a page reload goes <em>so</em> much faster if it doesn&#39;t have to download the
JavaScript every time.  Those libraries won&#39;t change for months!
If only the client browser knew that it could use the file that it had downloaded
last time.</p>

<p>The secret, of course, is to set the <code>Cache-Control</code> field of the HTTP header, but <em>how</em>?</p>

devdata/https_mojolicious.io_blog_2018_12_16_browser-diet_  view on Meta::CPAN

<a href="https://fiat-tux.fr/">Luc Didry</a>.
It sets the <code>Control-Cache</code> header for all static files served by Mojolicious.
With the <strong>nut.js</strong> and <strong>nut.css</strong> files in the <code>public</code> directory
(properly <a href="https://www.minifier.org/">minified</a> of course),
they should only be downloaded once and use the cached version until it expires.
The default <strong>max-age</strong> is 30 days and
if you want you can even cache during development with <code>even_in_dev =&gt; 1</code>.</p>

<p><img class="pull-right" src="speedtest_before_StaticCache.png"></p>

<p>The magpies in the forest had cluttered the calendar with 3 JavaScript libraries,
3 CSS files and 4 logos.  Sure, the biggest and shiniest was only 66 kB
and the whole collection was a paltry 164 kB, but bandwidth is precious in the wilderness.
Before using the StaticCache plugin, the calendar rated a
<strong>92</strong> on Google&#39;s PageSpeed Insights.</p>

<p>With the StaticCache plugin loaded</p>

<pre><code>sub startup {
    my $self = shift;

    $self-&gt;plugin(&#39;StaticCache&#39; =&gt; { even_in_dev =&gt; 1 });
    ...
}

devdata/https_mojolicious.io_blog_2018_12_20_testing-dancer_  view on Meta::CPAN

  -&gt;text_is(&#39;dl#data dt#hello + dd&#39;, &#39;world&#39;);

$t-&gt;post_ok(&#39;/html&#39; =&gt; form =&gt; { name =&gt; &#39;grinch&#39; })
  -&gt;status_is(200)
  -&gt;content_type_like(qr[text/html])
  -&gt;text_is(&#39;dl#data dt#hello + dd&#39;, &#39;grinch&#39;);

done_testing;
</code></pre>

<p>In this year&#39;s Mojolicious advent calendar, we&#39;ve already seen <a href="https://mojolicious.io/blog/2018/12/05/compound-selectors/">some</a> <a href="https://mojolicious.io/blog/2018/12/14/a-practical-example-of-mojo-dom/">great</a> <a hre...
The point remains however, testing HTML responses with CSS selectors allows you to make your tests targetd in a way that allows you to write more and better tests since you don&#39;t have to hack around extracting the bits you want.</p>

<h2>Testing WebSockets</h2>

<p>Ok so that&#39;s great and all, but of course now it comes to the point you&#39;ve all been waiting for: can you test WebSockets?
As Jason Crome mentioned in his <a href="http://advent.perldancer.org/2018/13">Twelve Days of Dancer</a> &quot;State of Dancer&quot;, you can now dance with WebSockets via <a href="https://metacpan.org/pod/Dancer2::Plugin::WebSocket">Dancer2::Plugin:...

<p>Well, so far not via the role I showed above.
It might be possible, but it would involve learning deep PSGI magick that I&#39;m not sure I&#39;m smart enough to do; patches welcome obviously :D.</p>

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

<p>Congratulations! we have served angular app with Mojolicious. Please note that the URL will be <code>http://localhost:8080/NgDemo/</code>.</p>

<h2>Integrating the Apps Further</h2>

<p>To show how the applications can interact, we&#39;ll now build a simple demo to show an api call to a Mojolicious backend routes from the Angular frontend and display the result in Angular.
Since, this is not an Angular blog I will not go too deep explaining Angular; there are plenty of resources in internet for that.</p>

<h3>Create a new route in the Mojo App</h3>

<p>Add a route <code>advent/2018/detail</code> in Mojolicious app class which just responds to http <code>get</code> request.
For some demo data, I&#39;ll just use the first articles from the 2018 Mojolicious advent calendar as a detail list.
In a full mojo app it is best to put routes methods in <code>AppName/Controller/SomeModule.pm</code>, but this is just for quick demo so we can use <a href="https://mojolicious.org/perldoc/Mojolicious/Guides/Growing#Simplified-application-class">hybr...

<pre><code>$r-&gt;get(&#39;advent/2018/detail&#39; =&gt; sub {
    my $self = shift;

    return $self-&gt;render(
        json =&gt;
            [
                {
                    title  =&gt; &#39;Welcome &amp; MojoConf Recap&#39;,

devdata/https_mojolicious.io_blog_2018_12_25_special-thanks_  view on Meta::CPAN

            </div>

              <div class="post-thumb">
                <!-- theme suggests 1300x500 -->
                <img alt="Baby Jude Carl Berger in Mojo gear" src="/blog/2018/12/25/special-thanks/jude_mojo.jpg">
              </div>

            <div class="post-content">

              <section id="section-1">
                  <p>This advent calendar, I have special thanks to offer to all the people who helped make it possible.
I&#39;ll list them shortly, but before I do, I&#39;d like to introduce you to the newest unofficial member of the Mojolicious Core Team: Jude Carl Berger!
Jude was born on the first day of this calendar, December 1st, at 2:15 am Chicago time.
If you&#39;re looking at timestamps, yes, that&#39;s about 4 hours after the first blog post went live.</p>

<p>After a one week stay in the NICU for a relatively minor condition, he&#39;s now home with myself and his mother, my wonderful wife Carolyn, who I have to thank first.
Not too many partners would put up with someone flitting out to edit a blog post or hit &quot;publish&quot; at the right moment during this time in our lives.
And thanks for Jude.</p>

<p>Armed with that knowledge, you can surely see that even more than usual I couldn&#39;t have done this without help!
So, with no further ado, I want to thank all the authors,</p>

<ul>

devdata/https_mojolicious.io_blog_2018_12_25_special-thanks_  view on Meta::CPAN

<li>Doug Bell</li>
<li>Jason Crome</li>
<li>Joe Cooper</li>
<li>Luc Didry</li>
<li>Sachin Dangol</li>
<li>Shawn Sorichetti</li>
</ul>

<p>I especially want to note that Doug Bell went above and beyond with eight (!) articles, brian d foy did more than his fair share with four, and Luc Didry and Boyd Duffee did two each!
I also want to specially mention Jason Crome who, during a tough month of his own, administered the <a href="http://advent.perldancer.org/2018">Twelve Days of Dancer</a> and contributed a cross-over article to ours as well.
The calendar is obviously nothing without the articles and so I&#39;m tremendously thankful that I had authors that I could lean on to help me when I wasn&#39;t able to fill extra space as I might have in other years.
Spectacular work, one and all!</p>

<p>We intend to publish more on this site throughout the year, including some pieces from two authors who submitted articles after all the days had been filled.
Articles had been committed to the repo, but were not yet published, which led to a small confusion in which these authors rose to meet a need they thought existed, so thank you Stefan Adams and Yuki Kimoto for stepping up!
We&#39;ll get those and other articles out to you in the coming months!</p>

<p>I want to thank Doug again for creating and maintaining <a href="http://preaction.me/statocles/">Statocles</a>, the static blog engine that powers this site.
I want to thank my employer <a href="https://www.servercentral.com/">ServerCentral</a> who not only are great to work for and support open source, but who gave me lots of time to get settled in with the newest member of my family (and a few cute gift...
I want to thank Sebastian Riedel for writing Mojolicious and for the outfit you see on Jude in the picture above (as far as I know, it is a unique piece), and the entire Mojolicious Core Team and community.</p>



( run in 0.600 second using v1.01-cache-2.11-cpan-c333fce770f )