Acme-CPANModulesBundle-Import-PerlDancerAdvent-2018

 view release on metacpan or  search on metacpan

devdata/http_advent.perldancer.org_2018_15  view on Meta::CPAN

</li>
</ul>
</div>


<div id="content">
<div class="pod-document"><h1><a name="dancer2__plugin__paginator___born_again"></a>Dancer2::Plugin::Paginator - Born Again</h1>

<h2><a name="history"></a>HISTORY</h2>

<p>I would call it re-birth. It all started during end of July 2017, I was going through the documentation of <a href="https://metacpan.org/pod/distribution/Dancer2/lib/Dancer2/Plugins.pod">Dancer2::Plugins</a> and stumbled upon <a href="https://meta...
<h2><a name="rebirth"></a>REBIRTH</h2>

<p>Following the <a href="http://neilb.org/2014/01/31/adoption-request.html">advise</a> from Neil Bowers, I contacted the author <b>Blabos de Blebe</b> by email, if he was happy for me take it forward. He not only encouraged me but also gave me permi...
<h2><a name="challenge"></a>CHALLENGE</h2>

<p>After getting the push from the author, my first challenge was to make it compatible with <a href="https://metacpan.org/pod/distribution/Dancer2/lib/Dancer2/Plugins.pod">Dancer2::Plugins</a>. Having done this with other plugins e.g. <a href="https...
<h2><a name="example"></a>EXAMPLE</h2>

<p>Let me show you an example as described in the official document for <a href="https://metacpan.org/release/Dancer2-Plugin-Paginator">Dancer2::Plugin::Paginator</a>.</p>
<pre class="prettyprint">use Dancer2;

devdata/http_advent.perldancer.org_2018_17  view on Meta::CPAN

};</pre>

<h2><a name="inline_images"></a>Inline images</h2>

<p>You can simply deliver emails with links to images, but usually email clients would not load them without user interaction.
It is possible though to attached the images to the email and reference them in the email body with a custom HTML tag:</p>
<pre class="prettyprint">    email {
        from      =&gt; 'foo@perl.dance',
        to        =&gt; 'bar@perl.dance',
        subject   =&gt; 'Welcome to the dancefloor!',
        body      =&gt; q{&lt;p&gt;Image embedded: &lt;img src="cid:mycid"/&gt;&lt;/p&gt;},
        type      =&gt; 'html',
        attach    =&gt; [ { Id =&gt; 'mycid', Path =&gt; '/dancefloor/dcr-header-logo.png' }],
        multipart =&gt; 'related'
};</pre>

<h2><a name="providing_plain_text_part"></a>Providing plain text part</h2>

<p><a href="https://metacpan.org/pod/HTML::FormatText::WithLinks">HTML::FormatText::WithLinks</a> makes it easy to provide a plain text version
of your HTML email:</p>
<pre class="prettyprint">my $html = template $template, $tokens, { layout =&gt; 'email' };

my $f    = HTML::FormatText::WithLinks-&gt;new;

devdata/http_advent.perldancer.org_2018_21  view on Meta::CPAN

    &lt;label class="visuallyhidden"&gt;Don't fill this in!&lt;input type="text" name="spam_one" tabindex="-1"&gt;&lt;/label&gt;
    &lt;input type="hidden" name="spam_two"&gt;

    &lt;input type="submit"&gt;Send Request&lt;/input&gt;
&lt;/form&gt;</pre>

<p>For the most part, it's a standard HTML form with a couple of notable exceptions:</p>
<pre class="prettyprint">&lt;label class="visuallyhidden"&gt;Don't fill this in!&lt;input type="text" name="spam_one" tabindex="-1"&gt;&lt;/label&gt;</pre>

<p>This uses a special CSS class, <code>visuallyhidden</code>, to make this form field invisible to the user. By giving it 
a <code>tabindex="-1"</code>, we make sure the user cannot accidentally tab to the field. There are still a few ways that 
field could accidentally get focus however, so we help the user here by giving it a label that says "Don't fill 
this in!"</p>
<p>What does <code>visuallyhidden</code> look like?</p>
<pre class="prettyprint">.visuallyhidden {
    border: 0;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;

devdata/http_advent.perldancer.org_2018_22  view on Meta::CPAN


<div id="content">
<div class="pod-document"><h1><a name="parameter_testing_with_dancer2__plugin__paramtypes"></a>Parameter testing with Dancer2::Plugin::ParamTypes</h1>

<p>The most common web code you will ever write is testing your parameters.
You might as well have a good way to do this.</p>
<h2><a name="in_the_old_ages"></a>In the old ages</h2>

<p>Way back then, we used to write code to check all of our arguments.</p>
<p>If we had a route that includes some ID, we would check that we
received it and that it matches the type we want. We would then decide
what to do if it doesn't match. Over time, we would clean up and
refactor, and try to reuse the checking code.</p>
<p>For example:</p>
<pre class="prettyprint">use Dancer2;
get '/:id' =&gt; sub {
    my $id = route_parameters-&gt;{'id'};
    if ( $id !~ /^[0-9]+$/ ) {
        send_error 'Bad ID' =&gt; 400;
    }

devdata/http_advent.perldancer.org_2018_22  view on Meta::CPAN

] =&gt; sub {...};</pre>

<p>In this form, the parameter <code>format</code> can be provided either in the
query string or in the body, because your route might be either a
<b>GET</b> or a <b>POST</b>.</p>
<h3><a name="register_type_actions"></a>Register type actions</h3>

<p>Type checking itself is the main role of this plugin, but you can also
control how it behaves.</p>
<p>The default action to perform when a type check fails is to error out,
but you can decide to act differently by registering a different
action.</p>
<pre class="prettyprint">register_type_action 'SoftError' =&gt; sub {
    my ( $self, $details ) = @_;

    warning "Parameter $details-&gt;{'name'} from $details-&gt;{'source'} "
          . "failed checking for type $details-&gt;{'type'}, called "
          . "action $details-&gt;{'action'}";

    return;
};



( run in 1.345 second using v1.01-cache-2.11-cpan-4505f990765 )