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

<h2><a href="/chart.html">Release Dashboard</a></h2>
</code></pre>

<p>But now I also need to replace the original landing page (index.html.ep)
so it can still be seen on the beta website. I do this with a simple
trick: I created a new template called <code>web.html+beta.ep</code> that imports
the original template and unsets the <code>variant</code> stash variable. Now
I can see the <a href="http://beta.cpantesters.org/web">main index page on the beta site at
http://beta.cpantesters.org/web</a>.</p>

<pre><code class="hljs">%= include &#39;index&#39;, variant =&gt; undef
</code></pre>

<pre><code>$ perl myapp.pl get /web -m beta
&lt;h1&gt;CPAN Testers&lt;/h1&gt;
&lt;p&gt;This is the main CPAN Testers application.&lt;/p&gt;
</code></pre>

<p>Template variants are a useful feature in some edge cases, and this isn&#39;t the
first time I&#39;ve found a good use for them. I&#39;ve also used them to provide a
different layout template in &quot;development&quot; mode to display a banner saying

devdata/https_mojolicious.io_blog_2017_12_12_day-12-more-than-a-base-class  view on Meta::CPAN

<p>The <code>has</code> keyword, added by the import above, gives us that nice declarative style that Perl users are familiar with from Moose and Moo.
The usage is different from those, owing to the limited choices available in declaration.
<code>has</code> takes a name or an array reference of name of the attribute(s) to declare.
It then optionally takes either a simple (non-reference) scalar default value or a callback to be used as a lazy builder.
When the lazy builder is called, it gets as an argument the instance itself.
That&#39;s it, clean and simple.</p>

<pre><code>package My::Class;
use Mojo::Base -base;

# attribute whose default is undef
has &#39;foo&#39;;

# two attribtues whose defaults are both 0
has [&#39;min&#39;, &#39;max&#39;] =&gt; 0;

# attribute that defaults to a new, empty hash reference
has &#39;data&#39; =&gt; sub { {} };

# attribute that uses its existing state to build
has &#39;double_max&#39; =&gt; sub {

devdata/https_mojolicious.io_blog_2017_12_18_day-18-the-wishlist-model  view on Meta::CPAN

    -&gt;hash;
}

<span class="hljs-keyword">sub </span><span class="hljs-function">list_user_names</span> {
  <span class="hljs-keyword">my</span> <span class="hljs-type">$self</span> = <span class="hljs-function">shift</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-type">$self</span><span class="hljs-type">
</span>    -&gt;sqlite
    -&gt;db
    -&gt;<span class="hljs-function">select</span>(
      &#39;<span class="hljs-string">users</span>&#39; =&gt; [&#39;<span class="hljs-string">name</span>&#39;],
      <span class="hljs-function">undef</span>,
      {-asc =&gt; &#39;<span class="hljs-string">name</span>&#39;},
    )
    -&gt;arrays
    -&gt;<span class="hljs-function">map</span>(<span class="hljs-keyword">sub</span>{ <span class="hljs-variable">$_</span>-&gt;[0] });
}

<span class="hljs-keyword">sub </span><span class="hljs-function">add_item</span> {
  <span class="hljs-keyword">my</span> (<span class="hljs-type">$self</span>, <span class="hljs-type">$user</span>, <span class="hljs-type">$item</span>) = <span class="hljs-type">@_</span>;
  <span class="hljs-type">$item</span>-&gt;{user_id} = <span class="hljs-type">$user</span>-&gt;{id};
  <span class="hljs-keyword">return</span> <span class="hljs-type">$self</span><span class="hljs-type">

devdata/https_mojolicious.io_blog_2017_12_20_day-20-practical-testing  view on Meta::CPAN


{
  <span class="hljs-keyword">package</span> <span class="hljs-keyword">Local</span>::MockLink;
  <span class="hljs-keyword">use</span> <span class="hljs-function">Mojo::Base</span> -base;
  has [qw/title url html/];
}

<span class="hljs-comment"># &quot;mock&quot; the link helper</span><span class="hljs-comment">
</span><span class="hljs-keyword">my</span> (<span class="hljs-type">$url</span>, <span class="hljs-type">$data</span>);
<span class="hljs-type">$t</span>-&gt;<span class="hljs-type">app</span>-&gt;<span class="hljs-type">helper</span>(&#39;<span class="hljs-string">link</span>&#39; =&gt; <span class="hljs-keyword">sub </span>{
  (<span class="hljs-function">undef</span>, <span class="hljs-type">$url</span>) = <span class="hljs-type">@_</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">Local</span>::MockLink-&gt;new(<span class="hljs-type">$data</span>);
});

<span class="hljs-type">$data</span> = {
  title =&gt; &#39;<span class="hljs-string">Cool Beans</span>&#39;,
  url =&gt; &#39;<span class="hljs-string">coolbeans.notasite</span>&#39;,
  html =&gt; &#39;<span class="hljs-string">&lt;p&gt;Some really Cool Beans&lt;/p&gt;</span>&#39;,
};

<span class="hljs-type">$t</span>-&gt;<span class="hljs-type">get_ok</span>(&#39;<span class="hljs-string">/add?url=coolbeans.notasite</span>&#39;)



( run in 1.458 second using v1.01-cache-2.11-cpan-d80b1682f3f )