Acme-CPANModulesBundle-Import-MojoliciousAdvent-2018

 view release on metacpan or  search on metacpan

LICENSE  view on Meta::CPAN

changed that file, and provided that you do at least ONE of the following:

  a) place your modifications in the Public Domain or otherwise make them
     Freely Available, such as by posting said modifications to Usenet or an
     equivalent medium, or placing the modifications on a major archive site
     such as ftp.uu.net, or by allowing the Copyright Holder to include your
     modifications in the Standard Version of the Package.

  b) use the modified Package only within your corporation or organization.

  c) rename any non-standard executables so the names do not conflict with
     standard executables, which must also be provided, and provide a separate
     manual page for each non-standard executable that clearly documents how it
     differs from the Standard Version.

  d) make other distribution arrangements with the Copyright Holder.

4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:

  a) distribute a Standard Version of the executables and library files,

devdata/https_mojolicious.io_blog_2018_12_07_openapi_  view on Meta::CPAN


            <div class="post-content">

              <section id="section-1">
                  <p>During this years <a href="http://www.olafalders.com/2018/11/21/metahack-3-wrap-report/">meta::hack 3</a>, I was extremely fortunate to work with <a href="https://twitter.com/joelaberger">Joel Berger</a> on integrating/documentin...

<h2>What is it?</h2>

<p>OpenAPI is a specification for designing, documenting, validating and driving your RESTful API. It can be used to provide documentation to an existing API, or when creating a new one.</p>

<p>The OpenAPI Specification originated as the Swagger specification and was renamed to separate the API description format (OpenAPI) from the open source tooling (Swagger). The specification moved into a new GitHub repository, but did not change.</p...

<p>In the case of the MetaCPAN API, we set out to provide documentation to the existing API, but quickly moved into supporting validation to API calls as well.</p>

              </section>
              <section id="section-2">
                  <h2>The tools</h2>

<p>OpenAPI has many tools available to help, including discovery tools that will assist in writing the specification. We chose to write the definition by hand (in vim of course) and use tools to generate the documentation and to integrate the specifi...

<ul>

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


<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;

sub main {
  # look in xml elements for laserscans that have hashes for names
  my $file = Mojo::File-&gt;new($path, &#39;pointclouds.xml&#39;);
  my $dom  = Mojo::DOM-&gt;new($file-&gt;slurp);
  # if &#39;Hash&#39; is populated, rename_files(); otherwise ignore
  for my $e ($dom-&gt;find(&#39;PointCloudData&#39;)-&gt;each) {
    $e-&gt;{Folder} = rename_files($e) and $e-&gt;{Hash} = &#39;&#39; if $e-&gt;{Hash};
  }
  # save xml file so we don&#39;t try to rename the pointclouds again
  $file-&gt;spurt($dom);
}

sub rename_files {
  # rename pointcloud folder and database file
  my $e = shift;
  my $newname = $e-&gt;{Folder} =~ s/$e-&gt;{Hash}/$e-&gt;{Name}/r;
  say &quot;renaming: $e-&gt;{Folder} to:\n$newname&quot;;
  rename $e-&gt;{Folder},       $newname       || die $!;
  rename $e-&gt;{Folder}.&#39;.db&#39;, $newname.&#39;.db&#39; || die $!;
  return ($newname);
}

main() if $path || die &#39;Please enter a path to the example files.&#39;;
</code></pre>

<h2>Not a web app</h2>

<p>Not every use of Mojolicious has to be a full app - parts of it can be used like any other Perl module. For a simple script, it can make getting to your actual purpose much quicker.  I use following line now all the time, even if I&#39;m not build...

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

my $dom  = Mojo::DOM-&gt;new($file-&gt;slurp);
</code></pre>

<p>In the <a href="https://cgi-lib.berkeley.edu/2.18/cgi-lib.pl.txt">bad old days</a>, I probably hand wrote 15 lines of (horrible) code every time I wanted to read a file.</p>

<h2>Mojo::DOM - what can&#39;t it do?</h2>

<p>And of course, <a href="https://mojolicious.org/perldoc/Mojo/DOM">Mojo::DOM</a> makes finding the right values in the XML easy - it also handles HTML and CSS selectors.  Basically, I just iterate through the contents of <code>PointCloudData</code>...

<pre><code>for my $e ($dom-&gt;find(&#39;PointCloudData&#39;)-&gt;each) {
  $e-&gt;{Folder} = rename_files($e) and $e-&gt;{Hash} = &#39;&#39; if $e-&gt;{Hash};
}
</code></pre>

<p>I only run <code>rename_files</code> if <code>Hash</code> is populated, and if it is, I empty it so I don&#39;t try to rename them again.  <code>rename_files</code> is about the only Perl code I had to write myself - almost everything else was cop...

<p>A substitution stores the desired file &amp; folder name in <code>$newname</code> (non-destructive modifier <code>/r</code> allows me to work on a copy of <code>$e</code> without changing the original).  Then I simply rename the point cloud folder...

<pre><code>my $newname = $e-&gt;{Folder} =~ s/$e-&gt;{Hash}/$e-&gt;{Name}/r;
</code></pre>

<p>When I&#39;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-&gt;spurt($dom)
</code></pre>

<p>The neat thing is, when I altered the contents of <code>$e-&gt;{Folder}</code> and <code>$e-&gt;{Hash}</code> in my loop, saving it back just works - I don&#39;t need to think too much about the XML structure at all.  Interestingly, saving <code>$...



( run in 0.805 second using v1.01-cache-2.11-cpan-e9daa2b36ef )