Acme-CPANModulesBundle-Import-MojoliciousAdvent-2018

 view release on metacpan or  search on metacpan

devdata/https_mojolicious.io_blog_2018_12_04_testing-hooks-and-helpers_  view on Meta::CPAN

$t->app->routes->get(
    '/test/exception' => sub { die "Exception" },
);
$t->get_ok( '/test/exception' )->status_is( 500 );
my $log_content = path( 'exception.log' )->slurp;
like $log_content, qr{Exception}, 'exception is logged';
done_testing;
</code></pre>

<p>Sure, this is technically testing a route. But, it&#39;s useful to know that
I can edit my application after I load it (but before any routes are
exercised). I often spawn additional Test::Mojo objects, sometimes using
the default
<a href="https://mojolicious.org/perldoc/Mojo/HelloWorld">Mojo::HelloWorld</a>
application to test different plugins.</p>

<h1>Helpers</h1>

<p>Now, I could test my helpers in the exact same way: Set up a new route
that uses my helper and examine the result. But, testing helpers can be
even easier: I can just ask the app to give me a controller with <a href="https://mojolicious.org/perldoc/Mojolicious#build_controller">the

devdata/https_mojolicious.io_blog_2018_12_06_making-a-list-with-yancy_  view on Meta::CPAN

    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name VARCHAR NOT NULL,
    address VARCHAR NOT NULL,
    is_nice BOOLEAN DEFAULT FALSE,
    is_delivered BOOLEAN DEFAULT FALSE
);
</code></pre>

<p>With our schema created, we can add
<a href="http://metacpan.org/pod/Yancy">Yancy</a>. Yancy is a simple CMS for
editing content and streamlining data-driven website development. We&#39;ll
tell Yancy to read our database schema to configure itself, but we&#39;ll
also give it a few hints to make editing content easier.</p>

<pre><code># Configure Yancy
plugin Yancy =&gt; {
    backend =&gt; { sqlite =&gt; $db },
    # Read the schema configuration from the database
    read_schema =&gt; 1,
    collections =&gt; {
        the_list =&gt; {
            # Show these columns in the Yancy editor
            &#39;x-list-columns&#39; =&gt; [qw( name address is_nice is_delivered )],
            properties =&gt; {
                # `id` is auto-increment, so hide it when creating rows
                id =&gt; { readOnly =&gt; 1 },
            },
        },
    },
};
</code></pre>

<p>If we run our app (<code>perl myapp.pl daemon</code>) and go to
<code>http://127.0.0.1:3000/yancy</code>, we can edit the list data.</p>

<p><img alt="Browser window showing a form to edit a list
entry" src="editor-form-screenshot.png"></p>

<p>Now Santa&#39;s data entry elves get to work entering the data for all the
people in the universe!</p>

<p><img alt="Browser window showing the list of data entered
in" src="editor-list-screenshot.png"></p>

<h1>Step 2: View The List</h1>

<p>With our data entry Neptunians working hard, we can build a way to view
the list. With four arms, they can enter data twice as fast!</p>

<p><img alt="Three Futurama Neptunians in front of baby strollers containing
one-eared rabbit dolls" src="neptunians.png"></p>

<p>Yancy comes with controllers that let us easily list our data just by

devdata/https_mojolicious.io_blog_2018_12_06_making-a-list-with-yancy_  view on Meta::CPAN

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

<h1>Step 3: Complete Delivery</h1>

<p>Santa&#39;s a busy robot, and all that ordnance is expensive. Once he&#39;s done
a delivery, he needs to mark it as done so he can move on to all the
other deserving people.</p>

<p><img alt="Santa Robot (from Futurama) writing on his list with a quill
pen" src="editing-list.png"></p>

<p>Stopping to check people off manually really slows down the murder and
mayhem.</p>

<p>Yancy makes it easy to update the data, this time with the <a href="https://metacpan.org/pod/Yancy::Controller::Yancy#set">&quot;set&quot; action
in Yancy::Controller::Yancy</a>:</p>

<pre><code># Set the delivered state of a list row
post &#39;/deliver/:id&#39;, {
    controller =&gt; &#39;yancy&#39;,

devdata/https_mojolicious.io_blog_2018_12_08_authenticating-with-ldap_  view on Meta::CPAN

ending with my solution on how to add LDAP authentication to your App.</p>

              </section>
              <section id="section-2">
                  <p>This post is based on a
<a href="https://docs.google.com/presentation/d/14ZbARlTj_3mxEf_9Bvbrz0AUYjQdFjIXfYuttb_J7uU">talk</a>
I gave at
<a href="https://act.yapc.eu/lpw2018">London Perl Workshop</a>
in 2018.
It&#39;s a little optimistic thinking that they&#39;ll get through
editing all the videos before Christmas, but we could hope
for an epiphany.
LDAP is just a small part of the authentication cycle here, so
this post generalises fairly well for those cases where you have
to write your own credential checker.
Oh, and the talk and writing this post has done exactly what was intended
and raised issues that I hadn&#39;t considered which I&#39;ve included here.
As a result, it&#39;s starting to read like
<a href="https://en.wikipedia.org/wiki/Alice%27s_Restaurant_Massacree">Alice&#39;s Restaurant</a>
without the full orchestration and five part harmony.
I hope this cautionary tale helps you to avoid the same pitfalls that I fell into.</p>

devdata/https_mojolicious.io_blog_2018_12_14_a-practical-example-of-mojo-dom_  view on Meta::CPAN

              <section id="section-2">
                  <h2>The task - simple, but tedious.</h2>

<p>3D models and drawings are fantastic tools, but in reality things are not so perfect.  Construction tolerances being what they are, our company relies a lot on <a href="https://www.youtube.com/watch?v=H-uNzEmt5sw">laser scanning</a>, where we go o...

<p>The problem is when our 3D modeling software (<a href="https://www.tekla.com/products/tekla-structures">Tekla Structures</a>) processes the point clouds, it changes the file names of each one from something human readable, such as <code>Pipe Rack ...

<p><img alt="Point clouds add information that is not available in the 3D model" src="pointcloud1.jpg">
<em>Point clouds provide critical information that is either too difficult or too costly to model directly</em></p>

<p>Fortunately, Tekla uses a lot of standard file formats that anyone can edit – including using XML to describe each point cloud it has processed.  Of course, I could just hand edit them to change the names, but that would have to be done for e...

<p>Conveniently, the XML file contains both the hash name and the original file name – so I knew I could use Mojo::DOM to parse the XML and rename the point clouds to be human readable. This simple task is the perfect example of how Mojolicious ...

<pre><code>#!/usr/bin/perl
use Mojo::Base -strict;
use Mojo::Util qw(getopt);
use Mojo::File;
use Mojo::DOM;

getopt &#39;p|path=s&#39; =&gt; \my $path;

devdata/https_mojolicious.io_blog_2018_12_15_practical-web-content-munging_  view on Meta::CPAN

                <img alt="An eyeball of alarming size" src="/blog/2018/12/15/practical-web-content-munging/banner.jpg">
              </div>

            <div class="post-content">

              <section id="section-1">
                  <p>Following brian d foy&#39;s great <a href="https://mojolicious.io/blog/2018/12/05/compound-selectors/">write-up of using Mojo::DOM selectors from Day 5</a>, I thought it&#39;d be fun to talk about some website migration scripts I...

<h2>From Static Site to Static Site Generator</h2>

<p>The problem I set out to solve was taking an old static website that was once hosted on SourceForge.net and migrating it to an exciting new...um...static website. But, this time, it&#39;ll be a modern take on a static website. Instead of editing H...

              </section>
              <section id="section-2">
                  <p>Hugo, like most modern static site generators, expects content to be in Markdown format with some metadata at the top of the file. I want to convert our crusty old HTML, as you&#39;ll see an example of below, into something that ...

<pre><code>---
title: &quot;Frobnitz 3.141593 released&quot;
date: 2016-10-10
description: &quot;This release includes a fog-flavored bauble of three equal sides, providing the restless...&quot;
categories: []

devdata/https_mojolicious.io_blog_2018_12_17_a-website-for-yancy_  view on Meta::CPAN

a website with a <a href="http://preaction.me/statocles">static site generator like
Statocles</a>, which is so popular these
days, I decided to do something wild and unpredictable: A dynamic
website! Lucky for me, I have the perfect project to easily build
a dynamic website: Yancy!</p>

              </section>
              <section id="section-2">
                  <p>The key part of any dynamic website is the database. Since I just want
to write Markdown and render HTML, my schema is quite simple: A place to
store the page&#39;s path, a place to store the page&#39;s Markdown for editing,
and a place to put the rendered HTML. I set up a SQLite database and
build the pages table using
<a href="https://metacpan.org/pod/Mojo::SQLite::Migrations">Mojo::SQLite::Migrations</a>.</p>

<pre><code>#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::SQLite;
helper db =&gt; sub {
    state $db = Mojo::SQLite-&gt;new( &#39;sqlite:&#39; . app-&gt;home-&gt;child( &#39;docs.db&#39; ) );
    return $db;

devdata/https_mojolicious.io_blog_2018_12_17_a-website-for-yancy_  view on Meta::CPAN

@@ migrations
-- 1 up
CREATE TABLE pages (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    path VARCHAR UNIQUE NOT NULL,
    markdown TEXT,
    html TEXT
);
</code></pre>

<p>With our database table prepared, I need a way to edit my pages. Yancy&#39;s
built-in editor comes with <a href="https://marked.js.org/">marked.js</a> to render
Markdown into HTML. I just need to tell it which column is Markdown and
where to store the HTML. We&#39;ll use the path as the ID to make it easy to
retrieve our pages.</p>

<pre><code>plugin &#39;Yancy&#39;, {
    backend =&gt; { Sqlite =&gt; app-&gt;db },
    read_schema =&gt; 1,
    collections =&gt; {
        pages =&gt; {
            &#39;x-id-field&#39; =&gt; &#39;path&#39;,

devdata/https_mojolicious.io_blog_2018_12_17_a-website-for-yancy_  view on Meta::CPAN

                    format =&gt; &#39;markdown&#39;,
                    &#39;x-html-field&#39; =&gt; &#39;html&#39;,
                },
            },
        },
    },
};
</code></pre>

<p>Now we can create some pages. I can start up the app with <code>perl myapp.pl
daemon</code>, and then edit my content by visiting
<code>http://127.0.0.1:3000/yancy</code>. The site will especially need an index
page, so I&#39;ll create one.</p>

<p><img alt="Screenshot showing the Yancy editor adding an &quot;index&quot;
page" src="edit-index.png">
<img alt="Screenshot showing the Yancy editor listing the index page in the
database" src="list-index.png"></p>

<p>With our content created, I need to add a route to display it. Using the
<a href="https://mojolicious.org/perldoc/Mojolicious/Guides/Routing#Wildcard-placeholders"><code>*</code> wildcard
placeholder</a>,
the route will match any path. I can then look up the page requested
from the database using the <a href="https://metacpan.org/pod/Yancy::Controller::Yancy/get">Yancy controller <code>get</code>
action</a>. I set
a default of &quot;index&quot; to pull our index page when users visit &quot;/&quot;. Last,
the route will need a little bit of a template just to display the

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


            <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>
<li>Boyd Duffee</li>
<li>brian d foy</li>
<li>Chris Seigman</li>
<li>Doug Bell</li>



( run in 1.062 second using v1.01-cache-2.11-cpan-de7293f3b23 )