Acme-CPANModulesBundle-Import-MojoliciousAdvent-2017

 view release on metacpan or  search on metacpan

devdata/https_mojolicious.io_blog_2017_12_07_day-7-using-template-variants-for-a-beta-landing-page  view on Meta::CPAN

                <span>Tagged in </span>:
                  <a href="/blog/tag/advent/">advent</a>,
                  <a href="/blog/tag/rendering/">rendering</a>,
                  <a href="/blog/tag/templates/">templates</a>
              </p>


                  <div class="bio cf">

                      <div class="gravatar">
                        <img alt="author image" src="https://secure.gravatar.com/avatar/4bdc4922059d58a0fcbf8f35652dc254.png">
                      </div>
                      <div class="about">
                        <h5>Doug Bell</h5>
                        <p>Doug (<a href="http://preaction.me">preaction</a>) is a long time Perl user.
He is the current maintainer of <a href="http://www.cpantesters.org/">CPAN Testers</a> and the author of many <a href="https://metacpan.org/author/PREACTION">CPAN modules</a> including the <a href="http://preaction.me/statocles/">Statocles</a> blog e...

                      </div>

                  </div>

devdata/https_mojolicious.io_blog_2017_12_08_day-8-mocking-a-rest-api  view on Meta::CPAN

                <span>Tagged in </span>:
                  <a href="/blog/tag/advent/">advent</a>,
                  <a href="/blog/tag/mocking/">mocking</a>,
                  <a href="/blog/tag/api/">api</a>
              </p>


                  <div class="bio cf">

                      <div class="gravatar">
                        <img alt="author image" src="https://secure.gravatar.com/avatar/4bdc4922059d58a0fcbf8f35652dc254.png">
                      </div>
                      <div class="about">
                        <h5>Doug Bell</h5>
                        <p>Doug (<a href="http://preaction.me">preaction</a>) is a long time Perl user.
He is the current maintainer of <a href="http://www.cpantesters.org/">CPAN Testers</a> and the author of many <a href="https://metacpan.org/author/PREACTION">CPAN modules</a> including the <a href="http://preaction.me/statocles/">Statocles</a> blog e...

                      </div>

                  </div>

devdata/https_mojolicious.io_blog_2017_12_15_day-15-start-a-new-yancy-app  view on Meta::CPAN

rendered HTML. There&#39;s plenty of customization options in <a href="http://metacpan.org/pod/Yancy#CONFIGURATION">the Yancy
configuration documentation</a>.</p>

<p>Now we can start up our app and go to <a href="http://127.0.0.1:3000/yancy">http://127.0.0.1:3000/yancy</a> to
manage our site&#39;s content:</p>

<pre><code>$ perl myapp.pl daemon
Server available at http://127.0.0.1:3000
</code></pre>

<p><img alt="Screen shot of adding a new blog item with Yancy" src="adding-item.png">
<img alt="Screen shot of Yancy after the new blog item is added" src="item-added.png"></p>

<p>Finally, we need some way to display our blog posts.  <a href="http://metacpan.org/pod/Mojolicious::Plugin::Yancy#HELPERS">Yancy provides
helpers to access our
data</a>. Let&#39;s
use the <code>list</code> helper to display a list of blog posts. This helper takes
a collection name and gives us a list of items in that collection. It
also allows us to search for items and order them to our liking. Since
we&#39;ve got a blog, we will order by the creation date, descending.</p>

<pre><code class="hljs">get &#39;<span class="hljs-string">/</span>&#39; =&gt; <span class="hljs-keyword">sub </span>{

devdata/https_mojolicious.io_blog_2017_12_15_day-15-start-a-new-yancy-app  view on Meta::CPAN

&lt;/main&gt;
</code></pre>

<p><a href="04-template.pl">Now we have our completed application</a> and we can test
to see our blog post:</p>

<pre><code>$ perl myapp.pl daemon
Server available at http://127.0.0.1:3000
</code></pre>

<p><img alt="The rendered blog post with our template" src="blog-post.png"></p>

<p>Yancy provides a rapid way to get started building a Mojolicious
application (above Mojolicious’s already rapid development). Yancy
provides a basic level of content management so site developers can
focus on what makes their site unique.</p>

              </section>
              <small><p><a href="http://www.publicdomainpictures.net/view-image.php?image=6416">Image</a> in the public domain.</p>
</small>

              <p class="tags">
                <span>Tagged in </span>:
                  <a href="/blog/tag/advent/">advent</a>,
                  <a href="/blog/tag/app/">app</a>
              </p>


                  <div class="bio cf">

                      <div class="gravatar">
                        <img alt="author image" src="https://secure.gravatar.com/avatar/4bdc4922059d58a0fcbf8f35652dc254.png">
                      </div>
                      <div class="about">
                        <h5>Doug Bell</h5>
                        <p>Doug (<a href="http://preaction.me">preaction</a>) is a long time Perl user.
He is the current maintainer of <a href="http://www.cpantesters.org/">CPAN Testers</a> and the author of many <a href="https://metacpan.org/author/PREACTION">CPAN modules</a> including the <a href="http://preaction.me/statocles/">Statocles</a> blog e...

                      </div>

                  </div>

devdata/https_mojolicious.io_blog_2017_12_17_day-17-the-wishlist-app  view on Meta::CPAN

<p>It is interesting to note that if we rendered this template directly, those buffers would all be empty.
Therefore the content put into them must come from someplace else.</p>

<h2>A Primary Template</h2>

<p>I mentioned before the the layout was like a container that would hold some inner content.
Let&#39;s consider the simplest such case.</p>

<p>When a user first accesses the site, the will be greeted with a login page.</p>

<p><img alt="Screen shot of the login page" src="login.png"></p>

<pre><code class="hljs">% title &#39;<span class="hljs-string">Welcome to the Wishlist!</span>&#39;;
% layout &#39;<span class="hljs-string">default</span>&#39;;

&lt;h2&gt;&lt;%= title %&gt;&lt;/h2&gt;

%= form_for &#39;<span class="hljs-string">login</span>&#39; =&gt; (method =&gt; &#39;<span class="hljs-string">POST</span>&#39;, class =&gt; &#39;<span class="hljs-string">form-inline</span>&#39;) =&gt; <span class="hljs-keyword">begin</span>
  &lt;div class=&quot;<span class="hljs-string">form-group</span>&quot;&gt;
    &lt;label&gt;Please <span class="hljs-function">tell</span> us your name to get started&lt;/label&gt;
    &lt;input name=&quot;<span class="hljs-string">name</span>&quot; class=&quot;<span class="hljs-string">form-control</span>&quot;&gt;

devdata/https_mojolicious.io_blog_2017_12_17_day-17-the-wishlist-app  view on Meta::CPAN

<h3>Routes</h3>

<p>The routes are mostly self explanatory, even if their code is not.
The <code>/login</code> and <code>/logout</code> handlers, for example.</p>

<p>There are two routes for <code>/add</code> a <code>GET</code> and a <code>POST</code>.
<code>GET</code> requests are safe and will not change data, in this case the request triggers LinkEmbedder to fetch the information which is then displayed.</p>

<h4>Adding Items</h4>

<p><img alt="Screen shot of the add items page" src="add.png"></p>

<pre><code class="hljs">% title &#39;<span class="hljs-string">Add an item</span>&#39;;
% layout &#39;<span class="hljs-string">default</span>&#39;;

% content_for &#39;<span class="hljs-string">head</span>&#39; =&gt; <span class="hljs-keyword">begin</span>
  &lt;style&gt;
    <span class="hljs-comment">#item-detail img {</span><span class="hljs-comment">
</span>      max-width: 40%;
      float: left;
      margin: <span class="hljs-number">20</span>px;

devdata/https_mojolicious.io_blog_2017_12_17_day-17-the-wishlist-app  view on Meta::CPAN

All our logout &quot;partial&quot; template does is generate a nicely formatted link to the log out route.
The name partial indicates that, like layout, this template is not intended to be rendered on its own.
The utility of making this its own template is that many pages can use that same partial to render that same log out link.</p>

<h4>The List</h4>

<p>There are two routes that might render a wishlist.
The <code>/</code> route either allows the user to log in or if they are, displays their list.
There is a also a <code>/list/:name</code> route that renders any user&#39;s list by name.</p>

<p><img alt="Screen shot of the list page" src="list.png"></p>

<pre><code class="hljs">% title user-&gt;{name} . &quot;<span class="hljs-string">&#39;s List</span>&quot;;
% layout &#39;<span class="hljs-string">default</span>&#39;;

% content_for &#39;<span class="hljs-string">sidebar</span>&#39; =&gt; <span class="hljs-keyword">begin</span>
  %= include &#39;<span class="hljs-string">partial/user_list</span>&#39;
  %= include &#39;<span class="hljs-string">partial/add_url</span>&#39;
  %= include &#39;<span class="hljs-string">partial/log_out</span>&#39;
% <span class="hljs-keyword">end</span>

devdata/https_mojolicious.io_blog_2017_12_21_day-21-virtually-a-lumberjack  view on Meta::CPAN


WIDTH=$(printf &quot;%08d&quot; $(tail -n+5 &quot;$FILE&quot; | head -n1 | tr -cd &#39; &#39; | wc -c));
HEIGHT=$(printf &quot;%08d&quot; $(echo $(wc -l &quot;$FILE&quot; | cut -f1 -d&#39; &#39;) - 4 | bc));

echo $WIDTH  | dd of=&quot;$FILE&quot; bs=1 seek=3  count=8 conv=notrunc
echo $HEIGHT | dd of=&quot;$FILE&quot; bs=1 seek=12 count=8 conv=notrunc
</code></pre>

<p>Now these are valid PGM images and we can open them to see the data stream!</p>

<p><img alt="Section of Yaw PGM" src="yaw.png"></p>

<p>(The above has been rotated and flipped, the original image is a thin
&quot;waterfall&quot;.)</p>

<p>Some parts are immediately obvious.
Very smooth gradients next to larger smooth blocks or gradients hints at a
high-precision timer, which tend to be 32 bits (4 bytes) wide.
This can be seen at the top of the example.</p>

<p>Other aspects are only noticeable when compared to the other movements.



( run in 1.386 second using v1.01-cache-2.11-cpan-2398b32b56e )