<?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: Graham Knop</title>
    <description>The latest articles on DEV Community by Graham Knop (@haarg).</description>
    <link>https://dev.to/haarg</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%2F580926%2Fe43e298c-dc25-4b95-bbd0-e7386e4e2a2d.png</url>
      <title>DEV Community: Graham Knop</title>
      <link>https://dev.to/haarg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/haarg"/>
    <language>en</language>
    <item>
      <title>Distar - A CPAN Distribution Author Tool</title>
      <dc:creator>Graham Knop</dc:creator>
      <pubDate>Wed, 31 Mar 2021 01:42:35 +0000</pubDate>
      <link>https://dev.to/haarg/distar-a-cpan-distribution-author-tool-5e95</link>
      <guid>https://dev.to/haarg/distar-a-cpan-distribution-author-tool-5e95</guid>
      <description>&lt;h1&gt;
  
  
  Basic CPAN Tooling
&lt;/h1&gt;

&lt;p&gt;When releasing a distribution on &lt;a href="https://www.cpan.org/"&gt;CPAN&lt;/a&gt;, authors need to include an installer script. Classically, this would be a &lt;code&gt;Makefile.PL&lt;/code&gt; using &lt;a href="https://metacpan.org/pod/ExtUtils::MakeMaker"&gt;ExtUtils::MakeMaker&lt;/a&gt; to generate a &lt;code&gt;Makefile&lt;/code&gt;, which would then be used with &lt;code&gt;make&lt;/code&gt;. Later, &lt;a href="https://metacpan.org/pod/Module::Build"&gt;Module::Build&lt;/a&gt; was created, using a &lt;code&gt;Build.PL&lt;/code&gt; script which served a similar purpose. The installer script would include information about the distribution, such as the name and prerequisites. This script, as well as the information inside it, would be used by a tool like &lt;a href="https://metacpan.org/pod/CPAN"&gt;CPAN.pm&lt;/a&gt; or &lt;a href="https://metacpan.org/pod/cpanm"&gt;cpanm&lt;/a&gt; to install the distribution and its prerequisites. This is the primary purpose of the tools, as something users interact with to test and install modules.&lt;/p&gt;

&lt;p&gt;But since authors always had the install tool at hand, it became a convenient place to put author tools as well. The primary of these would be &lt;code&gt;make dist&lt;/code&gt; which generates a distribution archive suitable for uploading to &lt;a href="https://www.cpan.org/"&gt;CPAN&lt;/a&gt;. For a long time, this was the primary way authors would create releases.&lt;/p&gt;

&lt;p&gt;However, as an author tool, &lt;a href="https://metacpan.org/pod/ExtUtils::MakeMaker"&gt;ExtUtils::MakeMaker&lt;/a&gt; leaves a lot to be desired. It uses a &lt;code&gt;MANIFEST&lt;/code&gt; file to list the files to include in the distribution, which won't include new files unless the author remembers to run &lt;code&gt;make manifest&lt;/code&gt;. And there are other sanity checks that authors should do before making a release that it doesn't provide for at all. Bumping version numbers, updating change logs, tagging and pushing to a VCS server. Some authors would build these tools into their &lt;code&gt;Makefile.PL&lt;/code&gt; script, but that can become a maintenance burden. Other tools, like &lt;a href="https://metacpan.org/pod/Module::Install"&gt;Module::Install&lt;/a&gt; were created to address some of this, by having a split between the author tools and user code, but it made some other problematic architectural choices.&lt;/p&gt;

&lt;h1&gt;
  
  
  Dist::Zilla
&lt;/h1&gt;

&lt;p&gt;These issues led to the creation of tools like &lt;a href="https://metacpan.org/pod/Dist::Zilla"&gt;Dist::Zilla&lt;/a&gt; which entirely separate the author tooling from the user tooling. It would also take over writing the &lt;code&gt;Makefile.PL&lt;/code&gt; script, since writing a proper &lt;code&gt;Makefile.PL&lt;/code&gt; is not trivial, and being able to include arbitrary code is usually unneeded. It is based on a plugin system, allowing authors to tailor its behavior to whatever release process they prefer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://metacpan.org/pod/Dist::Zilla"&gt;Dist::Zilla&lt;/a&gt; can be a fantastic tool, but comes with its own problems. There can be unexpected interactions between the multitude of plugins and versions, which can make the results of builds hard to reproduce without significant effort. It can also be difficult to express the desired build process via the plugin system, or to understand how it will behave by reading its configuration. The combination of these plugins often leads to a significant number of prerequisites, increasing the complexity and avenues of failure. It also regularly gets updated to take advantage of new perl features, which prevents it from being used on older perl versions&lt;sup id="fnref1"&gt;1&lt;/sup&gt;. These issues are all trade-offs made to allow it to be very feature full and extremely flexible.&lt;/p&gt;

&lt;h1&gt;
  
  
  Distar
&lt;/h1&gt;

&lt;p&gt;Not all authors agree with the trade-offs made by tools like &lt;a href="https://metacpan.org/pod/Dist::Zilla"&gt;Dist::Zilla&lt;/a&gt;. &lt;a href="https://metacpan.org/author/MSTROUT"&gt;Matt S Trout&lt;/a&gt; wanted an author tool, but started from a different perspective. What needs to be added on top of what &lt;a href="https://metacpan.org/pod/ExtUtils::MakeMaker"&gt;ExtUtils::MakeMaker&lt;/a&gt; provides to make it a viable author tool? The result of this thought process was &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; is a tool that adds just enough to &lt;a href="https://metacpan.org/pod/ExtUtils::MakeMaker"&gt;ExtUtils::MakeMaker&lt;/a&gt; so you can't bungle a release. And it is small enough to be able to read and understand the entire codebase at the same time.&lt;/p&gt;

&lt;p&gt;It uses an allowlist to include files in the dist, rather than &lt;a href="https://metacpan.org/pod/ExtUtils::MakeMaker"&gt;ExtUtils::MakeMaker&lt;/a&gt;'s normal denylist, preventing extraneous files in the working directory from being shipped. It makes certain that the &lt;code&gt;MANIFEST&lt;/code&gt; is up to date. It ensures you are testing against the same thing you are releasing. It forces you to add a Changelog entry for your release. It uploads to &lt;a href="https://www.cpan.org/"&gt;CPAN&lt;/a&gt;, and tags and pushes to git. And it does very little else.&lt;/p&gt;

&lt;p&gt;Since its creation, &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; has seen very little adoption. The only other &lt;a href="https://www.cpan.org/"&gt;CPAN&lt;/a&gt; author using it that I'm aware of is me. I've also done most of the development for the last several years, making it more robust, and including a few quality of life improvements like version bumping.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; does not make any changes from files in the repository vs the files shipped in the distribution. It generates a &lt;code&gt;README&lt;/code&gt;, a &lt;code&gt;LICENSE&lt;/code&gt; file, and the default files created by &lt;a href="https://metacpan.org/pod/ExtUtils::MakeMaker"&gt;ExtUtils::MakeMaker&lt;/a&gt;, &lt;code&gt;META.json&lt;/code&gt; and &lt;code&gt;META.yml&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  How Does Distar Work?
&lt;/h1&gt;

&lt;p&gt;To use &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt;, you start with a normal &lt;code&gt;Makefile.PL&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use ExtUtils::MakeMaker;
WriteMakefile(NAME =&amp;gt; "My::Cool::Module");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Before the call to &lt;code&gt;WriteMakefile&lt;/code&gt;, you add:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(do './maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since the &lt;code&gt;META.yml&lt;/code&gt; file is generated by &lt;a href="https://metacpan.org/pod/ExtUtils::MakeMaker"&gt;ExtUtils::MakeMaker&lt;/a&gt; in the distribution directory it creates, but not the working directory, it is a reliable check for "author mode" in a pure &lt;a href="https://metacpan.org/pod/ExtUtils::MakeMaker"&gt;EUMM&lt;/a&gt; environment.&lt;/p&gt;

&lt;p&gt;You then create the file &lt;code&gt;maint/Makefile.PL.include&lt;/code&gt; with the content:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN { -e 'Distar' or system qw(git clone https://github.com/p5sagit/Distar.git) }
use lib 'Distar/lib';
use Distar;

author 'A. U. Thor &amp;lt;author@cpan.org&amp;gt;';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; provides essentially no configuration aside from this. Any customization needed in the build process needs to be written in the &lt;code&gt;Makefile.PL&lt;/code&gt;, the same way it would be for raw &lt;a href="https://metacpan.org/pod/ExtUtils::MakeMaker"&gt;ExtUtils::MakeMaker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To make a release using &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt;, the process is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make bump           # bump version number
make nextrelease    # add changelog version heading
make release        # test &amp;amp; release
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  make release
&lt;/h2&gt;

&lt;p&gt;The core of &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; is the &lt;code&gt;release&lt;/code&gt; target. It does a number of sanity checks, then creates a release.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verify that the version numbers in all of the modules are matching.&lt;/li&gt;
&lt;li&gt;Verify that the &lt;code&gt;MANIFEST&lt;/code&gt; file is up to date.&lt;/li&gt;
&lt;li&gt;Verify that &lt;code&gt;cpan-upload&lt;/code&gt; is available to push to CPAN.&lt;/li&gt;
&lt;li&gt;Fetches any changes from the remote git server&lt;/li&gt;
&lt;li&gt;Verify that no git tag exists for the version being published.&lt;/li&gt;
&lt;li&gt;Verify that the release is being made from the master branch.&lt;/li&gt;
&lt;li&gt;Verify that there are no new commits on the remote git server.&lt;/li&gt;
&lt;li&gt;Verify that there is a version line in the Changelog that has been staged in git.&lt;/li&gt;
&lt;li&gt;Verify that there are no other uncommitted changes.&lt;/li&gt;
&lt;li&gt;Generate a dist directory, including a &lt;code&gt;README&lt;/code&gt; and &lt;code&gt;LICENSE&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;Run the tests in the dist directory, with &lt;code&gt;RELEASE_TESTING&lt;/code&gt; set.&lt;/li&gt;
&lt;li&gt;Create a git commit for the release.&lt;/li&gt;
&lt;li&gt;Create a git tag for the release.&lt;/li&gt;
&lt;li&gt;Create a dist tarball.&lt;/li&gt;
&lt;li&gt;Upload the dist tarball to &lt;a href="https://www.cpan.org/"&gt;CPAN&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Push the new tag and commit to the remote git server.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  make bump
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; provides a version bumping tool to modify any modules or &lt;code&gt;Makefile.PL&lt;/code&gt; containing the version number. It is meant to work with both numeric and dotted-decimal style versions. By default, it will bump the last segment of the dotted-decimal version, or the highest precision portion of a numeric version. It also provides other targets to bump specific parts of a version. When bumping a specific part of a version, numeric versions will be treated as &lt;code&gt;X.YYYZZZ&lt;/code&gt; versions, the same way perl versions work. Any components following the one specified will be reset to 0.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make bumpmajor                # bump the first digit component
make bumpminor                # bump the second digit component
make bumpbugfix               # bump the third digit component
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Other options can be used via the &lt;code&gt;V&lt;/code&gt; option.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make bump V=1.200             # bump to specific version
make bump V=--alpha           # bump last component, but add an underscore
                              # to indicate a developer release
make bump V='major --alpha'   # bump first digit component, but also add
                              # an underscore.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After bumping the version, the changes will be committed to git. This will work even if there are other changes in the working directory, leaving those changes uncommitted. The &lt;code&gt;Makefile.PL&lt;/code&gt; will then be re-run pick up the new version.&lt;/p&gt;

&lt;h2&gt;
  
  
  make nextrelease
&lt;/h2&gt;

&lt;p&gt;The release process of a &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; dist requires you to add a version line to your Changelog file, and stage that change (git add). The &lt;code&gt;nextrelease&lt;/code&gt; target will do this for you.&lt;/p&gt;

&lt;p&gt;It adds the version line, then uses git's interactive add on it, so you will need to confirm the changes. The diff shown should include all of the changelog entries written for the release.&lt;/p&gt;

&lt;h1&gt;
  
  
  git clone Distar
&lt;/h1&gt;

&lt;p&gt;The current way &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; is distributed is by adding code to &lt;code&gt;Makefile.PL&lt;/code&gt; which clones the repository and uses that. Some might think this would present a compatibility or stability issue, but the authors of &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; are very committed to maintaining stability and compatibility. Users have to trust that the authors will always keep the code in git in a working state. This trust has been easy to maintain so far, since the known users of &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; are its authors.&lt;/p&gt;

&lt;p&gt;There may be other users, since its code is small enough that others could understand it without needing any discussion with &lt;a href="https://metacpan.org/author/MSTROUT"&gt;Matt S Trout&lt;/a&gt; or myself.&lt;/p&gt;

&lt;p&gt;Not being published on &lt;a href="https://www.cpan.org/"&gt;CPAN&lt;/a&gt; limits the visibility of &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt;. I have, at times, thought of this as a feature. I've been uncertain if I wanted the pressure of additional users, and having to either accomodate or push back against alternate use cases and feature requests.&lt;/p&gt;

&lt;h1&gt;
  
  
  Should You Use Distar?
&lt;/h1&gt;

&lt;p&gt;I have no idea. It works well for me, and fits the model I have for creating releases. It isn't as fully automatic as many &lt;a href="https://metacpan.org/pod/Dist::Zilla"&gt;Dist::Zilla&lt;/a&gt; setups are, but it is extremely predictable, backwards compatible, and lightweight. It is very opinionated. It is unlikely to become more configurable to cover differing use cases.&lt;/p&gt;

&lt;p&gt;If others did like the idea of &lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt;, it may be time to look at improving the documentation and publishing it on CPAN.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/p5sagit/Distar"&gt;Distar&lt;/a&gt; is currently available on GitHub at &lt;a href="https://github.com/p5sagit/Distar"&gt;https://github.com/p5sagit/Distar&lt;/a&gt;.&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;It prevents authors from using older perl versions, but the CPAN releases it creates are still backward compatible. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

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