Acme-CPANModulesBundle-Import-PerlDancerAdvent-2018
view release on metacpan or search on metacpan
devdata/http_advent.perldancer.org_2018_15 view on Meta::CPAN
!window.jQuery && document.write('<script src="/javascripts/jquery.js"><\/script>')
/* ]]> */</script>
<!-- Prettyfy -->
<link href="/css/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/javascripts/prettify.js"></script>
</head>
<body onload="prettyPrint()">
<div id="page">
<div id="sidebar">
<a href="/" class="homelink">Dancer Advent Calendar</a><br />
<p>
The PerlDancer Advent Calendar is a community-driven project that aims
to showcase the Dancer Perl web framework.
</p>
<p>
Each day of December until Christmas, one article about Dancer. Stay tuned for new moves!
</p>
<ul id="sidebar-items">
<li>
<h3>About Dancer</h3>
<ul class="links">
<li><a href="http://www.perldancer.org/">Dancer homepage</a></li>
<li><a href="http://twitter.com/PerlDancer">Official Twitter</a></li>
<li><a href="http://github.com/PerlDancer/Dancer">Dancer on GitHub</a></li>
<li><a href="http://github.com/PerlDancer/Dancer2">Dancer 2 on GitHub</a></li>
<li><a class="feed" href="/feed/2018">RSS</a></li>
</ul>
</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;
use Dancer2::Plugin::Paginator;
get '/list' => sub {
my $paginator = paginator(
'curr' => $page,
'items' => rset('Post')->count,
'base_url' => '/posts/page/',
);
template 'list', { paginator => $paginator };
};
true;</pre>
<h2><a name="configuration"></a>CONFIGURATION</h2>
<p>To bring the above example live, we need to tune the configuration slightly as below.</p>
<pre class="prettyprint">plugins:
Paginator:
frame_size: 3
page_size: 7</pre>
<h2><a name="real_hands_on"></a>REAL HANDS-ON</h2>
<p>Having seen the details, now let us try real example. I have got GitHub repository that I use to try new things related to Dancer2 i.e. <a href="https://github.com/manwar/Dancer2-Cookbook">Dancer2 Cookbook</a>. You should find a link "Books" showi...
<h3><a name="example_configuration"></a>Example Configuration</h3>
<pre class="prettyprint">plugins:
Paginator:
frame_size: 1
page_size: 3</pre>
<h3><a name="action"></a>Action</h3>
<pre class="prettyprint">get '/books/:page' => sub {
my $books = _books();
my $curr = params->{page} || 1;
template 'books' => _paginator($books, $curr);
};
sub _paginator {
my ($books, $curr) = @_;
my $items = scalar(@$books);
my $paginator = paginator(
curr => $curr,
items => $items,
base_url => '/books',
mode => 'path'
);
my $page_size = $paginator->page_size;
my $i = ($curr - 1) * $page_size;
my $j = ($i + $page_size) - 1;
my $results = [ @$books[$i..$j] ];
return {
results => $results,
paginator => $paginator,
prev_l => $paginator->prev,
next_l => $paginator->next,
};
}</pre>
<h3><a name="template"></a>Template</h3>
( run in 0.728 second using v1.01-cache-2.11-cpan-ceb78f64989 )