view release on metacpan or search on metacpan
devdata/https_mojolicious.io_blog_2018_12_03_higher-order-promises_ view on Meta::CPAN
->race( @all_sites )
->then(
sub { say "One of them finished!" },
);
</code></pre>
<h3>Any</h3>
<p>An "any" Promise resolves immediately when the first of its Promises resolves. This is slightly different from <code>race</code> because at least one Promise must resolve. A Promise being rejected doesn't resolve the <code>any</code>...
<p>Here's a program that extracts the configured CPAN mirrors and tests that it can get the <em>index.html</em> file. To ensure that it finds that file and not some captive portal, it looks for "Jarkko" in the body:</p>
<pre><code>use v5.28;
use utf8;
use strict;
use warnings;
use feature qw(signatures);
no warnings qw(experimental::signatures);
use File::Spec::Functions;
use Mojo::Promise;
devdata/https_mojolicious.io_blog_2018_12_06_making-a-list-with-yancy_ view on Meta::CPAN
to automatically submit the form when the value is changed.</p>
<pre><code>%= javascript begin
// Automatically submit the form when an input changes
$( 'form input' ).change( function ( e ) {
$(this).parents("form").submit();
} );
% end
</code></pre>
<p>Now our webapp looks like this:</p>
<p><img alt="A browser window showing the completed webapp. A set of rows with name
and address on the left, and a Delivered button with Yes and No options
on the right. Some rows have the No button checked, others the Yes
button" src="finished-screenshot.png"></p>
<p>We can view our entire list, and check off the ones who we've delivered to already!
<a href="myapp.pl">View the entire app here</a>.</p>
<p><img alt="Santa Robot in his sleigh with burning buildings in the foreground and
devdata/https_mojolicious.io_blog_2018_12_08_authenticating-with-ldap_ view on Meta::CPAN
# this is where we check the password
my $login = $ldap->bind( $user_id, password => $password );
# return 1 on success, 0 on failure with the ternary operator
return $login->code == LDAP_INVALID_CREDENTIALS ? 0
: 1;
}
</code></pre>
<p>where you have a file <code>ldap_config.yml</code> in the top-level directory that looks a little like</p>
<pre><code># config values for connecting to LDAP
server: ldap.example.com
baseDN: dc=users,dc=example,dc=com
username: userid
id: dn
</code></pre>
<p>where the values on the right match the attributes in your LDAP schema.</p>
devdata/https_mojolicious.io_blog_2018_12_14_a-practical-example-of-mojo-dom_ view on Meta::CPAN
</code></pre>
<p>When I'm finished renaming the point clouds, I use <a href="https://mojolicious.org/perldoc/Mojo/File">Mojo::File</a> to save the contents of <code>$dom</code> back to <code>pointclouds.xml</code> with one line:</p>
<pre><code>$file->spurt($dom)
</code></pre>
<p>The neat thing is, when I altered the contents of <code>$e->{Folder}</code> and <code>$e->{Hash}</code> in my loop, saving it back just works - I don't need to think too much about the XML structure at all. Interestingly, saving <code>$...
<p><img alt="Point clouds are not perfect, but are still a valuable tool" src="pointcloud2.jpg">
<em>Note the grainy nature of the point cloud - since they are just points with no area, the closer you get, the grainier it looks</em></p>
<h2>Useful for all skill levels</h2>
<p>This is just one example of how I have used Mojolicious in my day job. Sometimes, existing software doesn't do what you want, or does it in a format that's not useful - problems that can be solved with the many tools Mojolicious provides....
<p>My next project idea is to rebuild a reporting tool I wrote for Material Take Offs (MTOs) to work with Tekla, which our engineers loved with our old modeling software - and I'm sure I will continue to find good uses for Mojolicious well into t...
</section>
<small><p>Original screenshots by maschine, released under CC-BY-SA 4.0.</p>
</small>
devdata/https_mojolicious.io_blog_2018_12_15_practical-web-content-munging_ view on Meta::CPAN
<section id="section-1">
<p>Following brian d foy'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'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'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'll see an example of below, into something that ...
<pre><code>---
title: "Frobnitz 3.141593 released"
date: 2016-10-10
description: "This release includes a fog-flavored bauble of three equal sides, providing the restless..."
categories: []
aliases: []
toc: false
draft: false
---
devdata/https_mojolicious.io_blog_2018_12_16_browser-diet_ view on Meta::CPAN
last time.</p>
<p>The secret, of course, is to set the <code>Cache-Control</code> field of the HTTP header, but <em>how</em>?</p>
</section>
<section id="section-2">
<h2>First, there was a <a href="https://httpd.apache.org/">Horse</a> ...</h2>
<p>Everybody using Apache would be thinking about using
<a href="https://httpd.apache.org/docs/2.4/mod/mod_expires.html">mod_expires</a>
which looks quite easy, except that Apache wasn't being used to serve the webpages.</p>
<p>... but the Horse mentioned where there were some sweet
<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control">Cache-Control directives</a>
to munch on and while continuing to graze on some
<a href="https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching">HTTP Caching</a>
pages that had been downloaded earlier. The small creature moves on.</p>
<h2>... and <em>then</em> there was a <a href="https://perlmaven.com/deploying-a-mojolicious-application">Toad</a></h2>
<p>The forest creatures used the
devdata/https_mojolicious.io_blog_2018_12_18_a-view-to-a-pod_ view on Meta::CPAN
}
</style>
<title><%= title %></title>
</head>
<body>
%= content
</body>
</html>
</code></pre>
<p>Now our documentation looks good!</p>
<p><img alt="Screenshot of Yancy module documenation with new style" src="good-docs.png"></p>
<p><a href="myapp.pl">Here's the full source</a>. Now that I have a beautiful
website, I just need to deploy the new site to the Internet...</p>
</section>
<small><p>Banner image CC0 Public Domain</p>
</small>
devdata/https_mojolicious.io_blog_2018_12_19_you-only-export-twice_ view on Meta::CPAN
Github</a> like all the cool people are doing.</p>
<p>But to do that, I'd need to take my dynamic website and turn it into a static
one, and that's impossible! Or is it? Why am I asking me, when I'm the one who
wrote a way to do it: The <a href="https://metacpan.org/pod/Mojolicious::Command::export">Mojolicious export
command</a>.</p>
</section>
<section id="section-2">
<p>The export command takes a set of paths as input, fetches those pages, and
writes the result to a directory. It then looks at all the links on those pages
and writes those pages, too. In this way, it exports an entire Mojolicious
website as static files.</p>
<p>All I need to do to be able to use the export command is to install it:</p>
<pre><code>$ cpanm Mojolicious::Command::export
</code></pre>
<p>Once it's installed, we now have the export command in our application which I
can use like any other Mojolicious command.</p>