<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Doug Bell</title>
    <description>The latest articles on DEV Community by Doug Bell (@preaction).</description>
    <link>https://dev.to/preaction</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F676033%2Fc79c342d-3cf0-4d13-80c2-08104615e424.jpeg</url>
      <title>DEV Community: Doug Bell</title>
      <link>https://dev.to/preaction</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/preaction"/>
    <language>en</language>
    <item>
      <title>A New Type of Mojolicious Frontend</title>
      <dc:creator>Doug Bell</dc:creator>
      <pubDate>Sun, 21 Nov 2021 23:02:19 +0000</pubDate>
      <link>https://dev.to/preaction/a-new-type-of-mojolicious-frontend-3i52</link>
      <guid>https://dev.to/preaction/a-new-type-of-mojolicious-frontend-3i52</guid>
      <description>&lt;p&gt;JavaScript has evolved quite a bit from its humble beginnings. Unfortunately, some of those advances have been difficult to take advantage of. Some require features not supported by all browsers, others require complicated tools. For my latest &lt;a href="https://mojolicious.org"&gt;Mojolicious&lt;/a&gt; web app, I wanted to see how I could use &lt;a href="https://www.typescriptlang.org"&gt;Typescript&lt;/a&gt; with a minimum of fuss.&lt;/p&gt;

&lt;p&gt;We'll start from a simple &lt;a href="https://docs.mojolicious.org/Mojolicious/Lite"&gt;Mojolicious::Lite&lt;/a&gt; app, created using &lt;code&gt;mojo generate lite_app&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;From there, we can install Typescript using &lt;a href="https://nodejs.org"&gt;Node&lt;/a&gt;. Since Typescript cannot bundle itself into a single file, we will also install &lt;a href="https://webpack.js.org"&gt;Webpack&lt;/a&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev typescript webpack webpack-cli ts-loader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After installation we can &lt;a href="https://www.typescriptlang.org/docs/handbook/tsconfig-json.html"&gt;configure Typescript using its tsconfig.json file&lt;/a&gt;. We'll use the &lt;code&gt;public&lt;/code&gt; directory for our output, since this directory is served by Mojolicious.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    "outDir": "./public/",
    "sourceMap": true,
    "noImplicitAny": true,
    "module": "es6",
    "target": "es5",
    "jsx": "react",
    "allowJs": true,
    "moduleResolution": "node"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We'll also need to configure Webpack's &lt;code&gt;webpack.config.js&lt;/code&gt; file to get it to bundle everything into a single &lt;code&gt;app.js&lt;/code&gt; file we can use. We'll have it start looking for our app in &lt;code&gt;src/index.ts&lt;/code&gt; and write our bundled app to &lt;code&gt;public/app.js&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require('path');

module.exports = {
  entry: './src/index.ts',
  devtool: 'inline-source-map',
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: [ '.ts', '.js' ],
  },
  output: {
    filename: 'app.js',
    path: path.resolve(__dirname, 'public'),
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With this complete, we can create a basic Typescript program.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/index.ts
function component() {
  const element = document.createElement('div');
  element.innerHTML = ['Hello,', 'Mojolicious!'].join(' ');
  return element;
}
document.body.appendChild(component());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can then build our Typescript program using Webpack:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx webpack
asset app.js 864 bytes [compared for emit] [minimized] (name: main)
./src/index.ts 196 bytes [built] [code generated]

webpack 5.64.2 compiled in 3123 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This creates &lt;code&gt;public/app.js&lt;/code&gt;, which we can then add to our Mojolicious app. To automatically rebuild our &lt;code&gt;app.js&lt;/code&gt; when needed, we can run &lt;code&gt;npx webpack --watch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For a complete example, see &lt;a href="https://github.com/preaction/mojo-typescript"&gt;this sample repository for a Mojolicious/Typescript app&lt;/a&gt;. As a bonus, you can get &lt;a href="https://dev.to/kraih/playwright-and-mojolicious-21hn"&gt;full end-to-end testing for your Mojolicious and Typescript web app using Playwright&lt;/a&gt;. With all this, you can bring the best that modern JavaScript has to offer to your Mojolicious web apps!&lt;/p&gt;

</description>
      <category>mojolicious</category>
      <category>typescript</category>
      <category>perl</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Yancy: What We Leave Behind</title>
      <dc:creator>Doug Bell</dc:creator>
      <pubDate>Thu, 04 Nov 2021 01:06:11 +0000</pubDate>
      <link>https://dev.to/preaction/yancy-what-we-leave-behind-509n</link>
      <guid>https://dev.to/preaction/yancy-what-we-leave-behind-509n</guid>
      <description>&lt;p&gt;When I started the &lt;a href="http://preaction.me/yancy"&gt;Yancy Content Management System&lt;/a&gt;, my goal was to see how easy it would be to build a generic admin editor on top of a &lt;a href="https://mojolicious.org"&gt;Mojolicious&lt;/a&gt; application database. Its design was, therefore, simple: A backend layer to talk to the database, a web application to view and edit the data, and an API controller to connect the two.&lt;/p&gt;

&lt;p&gt;Now, 4 years later, Yancy is on its way to becoming the M in Mojolicious &lt;a href="https://docs.mojolicious.org/Mojolicious/Guides/Growing#Model-View-Controller"&gt;MVC&lt;/a&gt;. I added &lt;a href="http://preaction.me/yancy/perldoc/Yancy/Model/"&gt;Yancy::Model&lt;/a&gt; as a place to keep data logic without the overhead of &lt;a href="https://metacpan.org/pod/DBIx::Class"&gt;DBIx::Class&lt;/a&gt;, but having a layer between the database backend and the web API enables all sorts of fun things, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Custom validation&lt;/li&gt;
&lt;li&gt;Packing and unpacking of complex data&lt;/li&gt;
&lt;li&gt;Automatic joining of related data&lt;/li&gt;
&lt;li&gt;Secondary, read-only backends and failover&lt;/li&gt;
&lt;li&gt;Transparent caching&lt;/li&gt;
&lt;li&gt;Data versioning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And these things can work across different backends: A caching module that uses Redis could be a frontend for a cache of a MySQL database or a Postgres database. The code only needs to be written once and made available on &lt;a href="https://cpan.org"&gt;CPAN&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Unfortunately, the new APIs take the place of some existing APIs and features that will have to be removed. These features were added to serve the frontend, but are awkward and limited in power compared to customizing the model API. The main features that have been deprecated are: Filters, Views, and OpenAPI.&lt;/p&gt;

&lt;p&gt;Filters were added to enable the frontend to do password hashing. By adding &lt;code&gt;x-filter&lt;/code&gt; to the configuration, a field or a row could have one or more filters applied to it before being written to the database. With the addition of the model API, filters can be added more easily and explicitly by creating a &lt;a href="http://preaction.me/yancy/perldoc/Yancy/Guides/Model/#Starting-a-Custom-Model"&gt;custom Schema class&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Views were a way to present subsets of data to a user through the frontend application. Instead of seeing all the raw information an application needs for a user, the editor could be made to show just the important information for the administrator or content manager. This, much like filters, can be done more robustly through the model API, or even directly through your database.&lt;/p&gt;

&lt;p&gt;Last, the &lt;a href="http://openapis.org"&gt;OpenAPI&lt;/a&gt; spec was how the frontend app analyzed the data schema to determine what it could do. However, since every schema can only do the same four operations (create, read, update, and delete), reading the OpenAPI spec to handle operations is needless complexity. The generated API could be used by more than just the Yancy editor, so the code for generating OpenAPI specs from Yancy schemas has been moved to &lt;a href="https://metacpan.org/pod/Yancy::Plugin::OpenAPI"&gt;the Yancy::Plugin::OpenAPI module on CPAN&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Yancy v2 has been &lt;a href="https://github.com/preaction/Yancy/issues/25"&gt;planned and in development for quite a while&lt;/a&gt;, but it is nearing completion. When v2 is released, these deprecated features will be removed. What will remain is a leaner, easier-to-use content management system for the best web framework out there.&lt;/p&gt;

</description>
      <category>mojolicious</category>
      <category>perl</category>
      <category>webdev</category>
      <category>yancy</category>
    </item>
    <item>
      <title>Yancy: The Next Model</title>
      <dc:creator>Doug Bell</dc:creator>
      <pubDate>Mon, 06 Sep 2021 18:15:36 +0000</pubDate>
      <link>https://dev.to/preaction/yancy-the-next-model-ndi</link>
      <guid>https://dev.to/preaction/yancy-the-next-model-ndi</guid>
      <description>&lt;p&gt;&lt;a href="http://preaction.me/yancy"&gt;Yancy&lt;/a&gt; is a &lt;a href="https://en.wikipedia.org/wiki/Content_management_system"&gt;content management system&lt;/a&gt; and application framework for the &lt;a href="https://mojolicious.org"&gt;Mojolicious&lt;/a&gt; web framework. For the last year, I've been using it to develop &lt;a href="https://metacpan.org/pod/Zapp"&gt;Zapp, my workflow automation webapp&lt;/a&gt;. Over that time, it became harder and harder to organize all the code needed to manipulate Zapp's data. To solve this problem, I wrote &lt;a href="http://preaction.me/yancy/perldoc/Yancy/Guides/Model"&gt;Yancy::Model&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Mojolicious is a &lt;a href="https://docs.mojolicious.org/Mojolicious/Guides/Growing#Model-View-Controller"&gt;Model-View-Controller (MVC) web framework&lt;/a&gt;. The model layer is where the data manipulation happens: Reading and writing records in the database. It is also where business logic happens: Sending e-mail for transactions, or periodic data cleanup. The goal of a model layer is to provide an API on to the application's data so that it can be used not only by the web application, but by other tools as well.&lt;/p&gt;

&lt;p&gt;Because &lt;a href="https://docs.mojolicious.org/Mojolicious/Guides/Growing#Model"&gt;Mojolicious does not provide its own model layer&lt;/a&gt;, most people usually turn to the &lt;a href="https://metacpan.org/pod/DBIx::Class"&gt;DBIx::Class ORM&lt;/a&gt;. But, this has always felt too complex and heavy for my needs: By the time I &lt;em&gt;know&lt;/em&gt; my project needs something like DBIx::Class, it's usually too late to migrate easily. I wanted something lighter and more agile that could grow from a rapidly-developed proof-of-concept app to the final, maintainable production version.&lt;/p&gt;

&lt;p&gt;Yancy provides a generic API on to multiple database systems, which it calls &lt;a href="http://preaction.me/yancy/perldoc/Yancy/Backend"&gt;Backends&lt;/a&gt;. Backends handle basic database operations with a common API. Using this common API, I built a lightweight class system for accessing data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://preaction.me/yancy/perldoc/Yancy/Model"&gt;Yancy::Model&lt;/a&gt; wraps the backend object and manages the classes.&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://preaction.me/yancy/perldoc/Yancy/Model/Schema"&gt;Yancy::Model::Schema&lt;/a&gt; provides methods to create and search a database table.&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://preaction.me/yancy/perldoc/Yancy/Model/Item"&gt;Yancy::Model::Item&lt;/a&gt; represents a single row in a table and provides methods to update and delete it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using these basic classes provides a more fluent interface to the database than using the backend API directly. But, the power of a model layer is in writing custom code to make managing the data easy and safe. For this, Yancy::Model allows you to add your own classes for schemas (tables) and items (rows).&lt;/p&gt;

&lt;p&gt;Writing custom model classes makes organizing your data management code easy. For example, Zapp has a table for workflows (called "plans") with a related table containing tasks ("plan_tasks") and another related table containing workflow input ("plan_inputs"). Whenever a user looks at a plan, they need to also see the plan's tasks and inputs. So, I can create a schema class that fetches this information automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nb"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;Zapp::Schema::&lt;/span&gt;&lt;span class="nv"&gt;Plans&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Mojo::&lt;/span&gt;&lt;span class="nv"&gt;Base&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yancy::Model::Schema&lt;/span&gt;&lt;span class="p"&gt;',&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;signatures&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;( $self, $id, %opt ) {&lt;/span&gt;
    &lt;span class="c1"&gt;# I could use two JOINs here instead, but joining &lt;/span&gt;
    &lt;span class="c1"&gt;# two 1:* relationships could result in a lot&lt;/span&gt;
    &lt;span class="c1"&gt;# of data to fetch and discard...&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$plan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$self&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nn"&gt;SUPER::&lt;/span&gt;&lt;span class="nv"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;%opt&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$inputs_schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$self&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;plan_inputs&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$plan&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$inputs_schema&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;list&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="s"&gt;plan_id&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;order_by&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rank&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;items&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$tasks_schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$self&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;plan_tasks&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$plan&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$tasks_schema&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;list&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="s"&gt;plan_id&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;order_by&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;task_id&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;items&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$plan&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zapp also has a table for recording every time a plan is run, called "runs". This table also records the tasks and inputs the plan had when it was run in "run_tasks" and "run_inputs" respectively (along with some additional fields to record the status of the tasks and the user's actual input). In a way, a run &lt;em&gt;is&lt;/em&gt; a plan. As above, when a user looks at a run, they need to also see the run's tasks and inputs. Since Yancy::Model uses plain Perl objects, I can refactor the plans class to also handle runs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nb"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;Zapp::Schema::&lt;/span&gt;&lt;span class="nv"&gt;Plans&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Mojo::&lt;/span&gt;&lt;span class="nv"&gt;Base&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yancy::Model::Schema&lt;/span&gt;&lt;span class="p"&gt;',&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;signatures&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="s"&gt;tasks_table&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;plan_tasks&lt;/span&gt;&lt;span class="p"&gt;';&lt;/span&gt;
&lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="s"&gt;inputs_table&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;plan_inputs&lt;/span&gt;&lt;span class="p"&gt;';&lt;/span&gt;
&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;( $self, $id, %opt ) {&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$plan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$self&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nn"&gt;SUPER::&lt;/span&gt;&lt;span class="nv"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;%opt&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$inputs_schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$self&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$self&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;inputs_schema&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$plan&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$inputs_schema&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;list&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="s"&gt;plan_id&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;order_by&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rank&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;items&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$tasks_schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$self&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$self&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;tasks_schema&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$plan&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$tasks_schema&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;list&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="s"&gt;plan_id&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;order_by&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;task_id&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;items&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$plan&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;Zapp::Schema::&lt;/span&gt;&lt;span class="nv"&gt;Runs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Mojo::&lt;/span&gt;&lt;span class="nv"&gt;Base&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Zapp::Schema::Plans&lt;/span&gt;&lt;span class="p"&gt;',&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;signatures&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="s"&gt;tasks_table&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;run_tasks&lt;/span&gt;&lt;span class="p"&gt;';&lt;/span&gt;
&lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="s"&gt;inputs_table&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;run_inputs&lt;/span&gt;&lt;span class="p"&gt;';&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now plans and runs both fetch their related data automatically. I can add similar functionality to &lt;code&gt;create&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt;, &lt;code&gt;list&lt;/code&gt;, and &lt;code&gt;delete&lt;/code&gt; to make dealing with the related data seamless. Further, I can create completely custom methods like &lt;code&gt;enqueue&lt;/code&gt; which will add the plan (or the run) to the &lt;a href="https://docs.mojolicious.org/Minion"&gt;Minion job queue&lt;/a&gt; to be executed.&lt;/p&gt;

&lt;p&gt;With &lt;a href="http://preaction.me/yancy/perldoc/Yancy/Guides/Model/"&gt;Yancy::Model&lt;/a&gt; I can quickly build an API for my application's data. As my application develops, I can keep my data logic separate from my web frontend logic. Since they're separate, I can use my data logic in other applications and tools. This is the biggest benefit of using an MVC pattern with a framework like &lt;a href="http://mojolicious.org"&gt;Mojolicious&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>perl</category>
      <category>mojolicious</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Zapp: Runbook Automation</title>
      <dc:creator>Doug Bell</dc:creator>
      <pubDate>Thu, 29 Jul 2021 00:08:12 +0000</pubDate>
      <link>https://dev.to/preaction/zapp-runbook-automation-451g</link>
      <guid>https://dev.to/preaction/zapp-runbook-automation-451g</guid>
      <description>&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/preaction" rel="noopener noreferrer"&gt;
        preaction
      &lt;/a&gt; / &lt;a href="https://github.com/preaction/Zapp" rel="noopener noreferrer"&gt;
        Zapp
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Create plans for your Minions to run
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;I hate runbooks. I've been an SRE from since we were called webmasters. In all this time, the least helpful part of my job has been the lists of commands to run when there's a problem. Often out-of-date, frequently lacking in context, and altogether useless when production is burning around you and clients are banging on the door. I'm a programmer. I don't perform tedious tasks, I automate them. Why, then, should I like documenting tedious tasks?&lt;/p&gt;

&lt;p&gt;I hate &lt;a href="https://www.jenkins.io" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt;. No, that's not quite true. I'm disappointed in Jenkins. Parameterized builds could be such a useful tool, but the input form they provide the end-user is ugly at best, incomprehensible at worst. Jenkins's pipeline syntax opens the door to some truly amazing abilities, but there's no way for me to package those abilities in a way I can simply give to someone without training them on how to navigate Jenkins's UI.&lt;/p&gt;

&lt;p&gt;To solve these problems, I wrote &lt;a href="https://metacpan.org/pod/Zapp" rel="noopener noreferrer"&gt;Zapp&lt;/a&gt;. In Zapp, I can create a plan as a series of tasks, like a Jenkins build. Plans can have input fields, like a Jenkins parameterized build. Users can then run the plan and see the output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://metacpan.org/pod/Zapp::Task" rel="noopener noreferrer"&gt;Zapp tasks&lt;/a&gt; can be more than a shell command or script. Zapp tasks have their own configuration, so I can provide a friendly form for the user to control what the task will do. Additionally, tasks output typed data that can be used as input to subsequent tasks. When the task executes, it can render its own output to show the end-user what is happening.&lt;/p&gt;

&lt;p&gt;So, I can create a plan that asks a user to input their credentials.&lt;br&gt;
￼&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foju8cu23smeu63n50cgz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foju8cu23smeu63n50cgz.png" alt="Zapp form showing two inputs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, the plan can fetch an authentication token using those credentials.&lt;br&gt;
￼&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3lc9csiticip0wwy3k3r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3lc9csiticip0wwy3k3r.png" alt="Zapp form for GetOAuth2Token task"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, with this authentication token, I can perform my request.&lt;br&gt;
￼&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl3ar28jn017sgj4hso64.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl3ar28jn017sgj4hso64.png" alt="Zapp form for Request task"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then when I want to run the plan, I can input my credentials and hit a button. &lt;br&gt;
￼&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuicug5womej7sklgvc4w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuicug5womej7sklgvc4w.png" alt="Zapp form to run the plan"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As the job runs, it updates the job page. If any errors occur, the job stops and the failing task shows an error message. I can choose to re-play the job, or I can go back and fix whatever problem there is.&lt;/p&gt;

&lt;p&gt;Zapp isn't limited to automating runbooks. Zapp provides webhook triggers to perform plans automatically. Build your software after a commit is pushed to Github, respond to Slack commands, or (when a future version adds scheduled tasks) run a nightly SQL report. Not only are these tasks automated, but they are easy to configure so that users can support themselves.&lt;/p&gt;

&lt;p&gt;Finally, if Zapp can't do what you want, you can write your own task classes to perform tasks, type classes to accept input from users, and trigger classes to run plans automatically in response to events. Zapp is written in modern Perl using the Mojolicious web framework and the Minion task runner.&lt;/p&gt;

&lt;p&gt;With Zapp, I can make tedious support processes into a single web form, or even a single click. As needs change, processes can be tweaked using a friendly UI. And new types of tasks can be created to provide ever more options for your users.&lt;/p&gt;

&lt;p&gt;Zapp is very much Alpha-grade software right now: I use it personally, but there are bugs and missing features yet. The plugin APIs are pretty solid, though, so you can write your own tasks, types, and triggers. There are a lot of features that Minion provides that Zapp does not yet take advantage of, so there's plenty of possibilities for future development. If you have any questions, suggestions, issues, or want to know if Zapp can work for you, feel free to let me know at &lt;a href="mailto:doug@preaction.me"&gt;doug@preaction.me&lt;/a&gt; or on &lt;a href="https://web.libera.chat/#mojo-yancy" rel="noopener noreferrer"&gt;irc.libera.chat in #mojo-yancy&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>perl</category>
      <category>mojolicious</category>
    </item>
  </channel>
</rss>
