<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sirhc.us maxim.us &#187; laziness</title>
	<atom:link href="http://sirhc.us/tag/laziness/feed/" rel="self" type="application/rss+xml" />
	<link>http://sirhc.us</link>
	<description>the pathological prattle of a primal perl programmer</description>
	<lastBuildDate>Sat, 19 May 2012 21:07:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Automating On Call Jury Instructions</title>
		<link>http://sirhc.us/automating-on-call-jury-instructions/</link>
		<comments>http://sirhc.us/automating-on-call-jury-instructions/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 00:32:52 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[jury duty]]></category>
		<category><![CDATA[laziness]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://sirhc.us/?p=913</guid>
		<description><![CDATA[A version of this article is also published on my Perl blog. Early in February, I received a jury summons for the United States District Court, Southern District of California. Prospective jurors for federal jury service (at least in this &#8230; <a href="http://sirhc.us/automating-on-call-jury-instructions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>A version of this article is also published on my <a href="http://blogs.perl.org/users/sirhc/2012/04/automating-on-call-jury-instructions.html">Perl blog</a>.</em></p>
<p>Early in February, I received a jury summons for the United States District Court, Southern District of California.  Prospective jurors for federal jury service (at least in this court) are placed on call for a period of about 30 days.  I was to call for instructions on April 1 and potentially proceed to do so periodically until May 4 (assuming I wasn&#8217;t instructed to report).</p>
<p>Since my initial instruction date was nearly two months away, I created an entry for it in Google Calendar, and promptly forgot about it.  On Monday, April 2, I was riding the train to work when I realized that I hadn&#8217;t remembered to check my instructions.  Fortunately, after arriving at my office and checking my instructions, I had been deferred to the next day.</p>
<p>So I added a new entry in Google Calendar, this time with an SMS reminder.  I proceeded to do this for most of April, checking my instructions and duplicating the calender entry with another SMS reminder.</p>
<p>I&#8217;m embarrassed to admit that it wasn&#8217;t until the last week of April that it occurred to me that I could automate the whole process.  After all, isn&#8217;t automating drudgery the whole reason I ended up programming Perl in an engineering support group at my day job?</p>
<p>In addition to a telephone recording, jury instructions can be <a href="http://jury.casd.uscourts.gov/AppearWeb/Default.aspx">obtained online</a>.  In fact, this is the method I used all month.  The form uses the HTTP POST method, so it wasn&#8217;t a simple matter of constructing an URL to fetch my instructions.  While I could construct a POST request with <tt>curl(1)</tt> or the <tt>LWP</tt> module, it&#8217;s so much easier to do with with the <a href="https://metacpan.org/module/WWW::Mechanize"><tt>WWW::Mechanize</tt></a> module.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mech</span> <span style="color: #339933;">=</span> WWW<span style="color: #339933;">::</span><span style="color: #006600;">Mechanize</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$mech</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'http://jury.casd.uscourts.gov/AppearWeb/Default.aspx'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$mech</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">submit_form</span><span style="color: #009900;">&#40;</span>
    form_name <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Form1'</span><span style="color: #339933;">,</span>
    fields    <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #ff0000;">'ctl02$txtPart'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'PARTICIPANT_ID'</span><span style="color: #339933;">,</span>
        <span style="color: #ff0000;">'ctl02$txtZip'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'ZIP_CODE'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    button <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'ctl02$btnInstructions'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>When I&#8217;m not supposed to report, the following message appears in the returned content:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;span id=&quot;ctl02_lblMsg&quot;&gt;Please check again Sunday, April 29, after 6:00pm for further reporting instructions. Do NOT report at this time.&lt;/span&gt;</pre></div></div>

<p>Given how simple this is, I could parse it with a regular expression.  But, I figured it was worth trying to do it right, so I searched CPAN and found the <a href="https://metacpan.org/module/HTML::DOM"><tt>HTML::DOM</tt></a> module.  I&#8217;ve worked a bit with DOM in JavaScript, so the module appealed to me.  Annoyingly, the parse method only supports file names or file handles.  Fortunately, this isn&#8217;t terribly difficult to work around and the whole thing isn&#8217;t much more verbose than using a regular expression.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dom</span> <span style="color: #339933;">=</span> HTML<span style="color: #339933;">::</span><span style="color: #006600;">DOM</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">parse_file</span><span style="color: #009900;">&#40;</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Scalar</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span> <span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$mech</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">content</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">\$c</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'ctl02_lblMsg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">innerHTML</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now that I have the message what does it say?  Thus far my instructions have always been to check again on another day, so I&#8217;ll need to work with what I know and defensively code for the exceptions.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$message</span> <span style="color: #339933;">!~</span> <span style="color: #009966; font-style: italic;">/Do NOT report at this time/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># We didn't see the message we wanted to see, so we'd better alert...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If I don&#8217;t see the known message, I send myself an alert (I happened to use the <a href="https://metacpan.org/module/Email::Sender"><tt>Email::Sender</tt></a> module in the script) and exit.  If this happens, I&#8217;ll need to address it as it probably means I need to report (or I&#8217;m no longer on call).</p>
<p>However, if I do see the above message, I need to figure out when I&#8217;m supposed to check again.  If this fails for some reason (e.g., I don&#8217;t know what the format looks like if the day is a single digit), I go through the alert process again.  It&#8217;s rather important that this script be noisy, given the nature of what I&#8217;m doing and the limited knowledge I&#8217;m working with.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$message</span> <span style="color: #339933;">!~</span> <span style="color: #009966; font-style: italic;">/Please check again (?&lt;weekday&gt;\w+), (?&lt;month&gt;\w+) (?&lt;day&gt;\d+)/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># We couldn't parse the next date to check, so we'd better alert...</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dt</span> <span style="color: #339933;">=</span> DateTime<span style="color: #339933;">::</span><span style="color: #006600;">Format</span><span style="color: #339933;">::</span><span style="color: #006600;">DateParse</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">parse_datetime</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$+{'weekday'}, $+{'day'} $+{'month'} 18:15&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I&#8217;ve hard-coded the time to check as 6:15 PM, because the instructions are always updated at 6:00 PM.</p>
<p>Finally, the script schedules itself to run again at the time indicated.  Here I&#8217;ve broken out of Perl to use the <a href="http://linux.die.net/man/1/at"><tt>at(1)</tt></a> command.  Since I&#8217;m running the script on my Linode VPS, this seemed an easy way to accomplish the task of rescheduling.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000066;">open</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$at</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'|-'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'at'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$dt</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">strftime</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'%R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$dt</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">strftime</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'%F'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
say <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$at</span><span style="color: #009900;">&#125;</span> <span style="color: #ff0000;">&quot;$0 2&gt;/dev/null&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># $0 must be fully qualified or in PATH</span>
<span style="color: #000066;">close</span> <span style="color: #0000ff;">$at</span><span style="color: #339933;">;</span></pre></div></div>

<p>Running this script once will set the rescheduling process in motion, alleviating me of the need to run it again.  If I&#8217;d thought of this at the beginning of April, I could have forgotten about the whole bother of checking for instructions several times per week.  Oh well, live and learn.</p>
<p>I&#8217;ve posted the full script as a <a href="https://gist.github.com/2522558">Gist</a> on GitHub.</p>
<p>As a way of outsourcing the work and perhaps offer this type of service to a wider audience, I looked at <a href="http://ifttt.com/dashboard">ifttt</a> and <a href="http://pipes.yahoo.com/pipes/">Yahoo! Pipes</a>.  Unfortunately, the former doesn&#8217;t appear to have a way to trigger on scraping an arbitrary web page, and the latter doesn&#8217;t appear to support the HTTP POST method.  If anyone knows of an approach using existing services, I&#8217;m open to suggestions.</p>
<p><em>Updated on 30 April 2012.</em></p>
<h2><tt>Mojo::UserAgent</tt></h2>
<p>Posting this on <a href="http://blogs.perl.org/">blogs.perl.org</a> resulted in a few comments (including a rant I completely agree with, but that&#8217;s beside the point).  There was one suggestion that I try using <a href="https://metacpan.org/module/Mojo::UserAgent"><tt>Mojo::UserAgent</tt></a> instead of <tt>WWW::Mechanize</tt>.</p>
<p>My first attempt at doing so wasn&#8217;t particularly successful.  After a while, I realized that I needed to manually do some of the work that <tt>WWW::Mechanize</tt> was doing for me.  Namely, fetch the page, extract the hidden fields, and submit the form with these fields included (there&#8217;s a cookie involved, but it&#8217;s taken care of behind the scenes by both modules).</p>
<p>Because of this, the <tt>Mojo::UserAgent</tt> version is a bit more annoying to write, but I think this is more than made up for by the built-in access to the DOM.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ua</span>  <span style="color: #339933;">=</span> Mojo<span style="color: #339933;">::</span><span style="color: #006600;">UserAgent</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$url</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'http://jury.casd.uscourts.gov/AppearWeb/Default.aspx'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$res</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ua</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">res</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;"># initial fetch to get cookie and form fields</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$tx</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ua</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">max_redirects</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">post_form</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">$url</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #ff0000;">'__VIEWSTATE'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">dom</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'form#Form1 &gt; input#__VIEWSTATE'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">attrs</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #ff0000;">'__EVENTVALIDATION'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">dom</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'form#Form1 &gt; input#__EVENTVALIDATION'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">attrs</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #ff0000;">'ctl02$txtPart'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'PARTICIPANT_ID'</span><span style="color: #339933;">,</span>
        <span style="color: #ff0000;">'ctl02$txtZip'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'ZIP_CODE'</span><span style="color: #339933;">,</span>
        <span style="color: #ff0000;">'ctl02$btnInstructions'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Reporting Instructions'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$res</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$tx</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">success</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$tx</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">error</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">dom</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'span#ctl02_lblMsg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">text</span><span style="color: #339933;">;</span></pre></div></div>

<h2><tt>WWW::Scripter</tt></h2>
<p>As I was working on the <tt>Mojo::UserAgent</tt> version of my script, I kept thinking how perfect it would be if <tt>WWW::Mechanize</tt> gave me access to the DOM in the same way.  Well, as I was pushing the new <tt>jury-mojo.pl</tt> script to my Gist, <a href="https://gist.github.com/cpansprout">cpansprout</a> left a comment to not only tell me how I could remove my <tt>IO::Scalar</tt> hack, but that <tt>WWW::Scripter</tt> does exactly what I had just been wishing for.  It&#8217;s like he read my mind.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mech</span> <span style="color: #339933;">=</span> WWW<span style="color: #339933;">::</span><span style="color: #006600;">Scripter</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$mech</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'http://jury.casd.uscourts.gov/AppearWeb/Default.aspx'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$mech</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">submit_form</span><span style="color: #009900;">&#40;</span>
    form_name <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Form1'</span><span style="color: #339933;">,</span>
    fields    <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #ff0000;">'ctl02$txtPart'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'PARTICIPANT_ID'</span><span style="color: #339933;">,</span>
        <span style="color: #ff0000;">'ctl02$txtZip'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'ZIP_CODE'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    button <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'ctl02$btnInstructions'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$mech</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">document</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'ctl02_lblMsg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">innerHTML</span><span style="color: #339933;">;</span></pre></div></div>

<p>I like this last version the most and have updated my Gist accordingly.  Also, my automation worked and emailed me tonight to inform me that my jury service has concluded.</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/automating-on-call-jury-instructions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSCON 2010: Dist::Zilla</title>
		<link>http://sirhc.us/oscon-2010-distzilla/</link>
		<comments>http://sirhc.us/oscon-2010-distzilla/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 19:11:01 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[cpan]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Dist::Zilla]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[laziness]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon2010]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=511</guid>
		<description><![CDATA[Ricardo Signes (Pobox.com) The full title of this talk is, Dist::Zilla &#8211; Maximum Overkill for CPAN Distributions. Every CPAN distribution contains a significant amount of crap. It&#8217;s infrastructure used for the distribution tools. ExtUtils::MakeMaker has been the traditional way to &#8230; <a href="http://sirhc.us/oscon-2010-distzilla/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.oscon.com/oscon2010/public/schedule/speaker/3189"><em>Ricardo Signes (Pobox.com)</em></a></p>
<p>The full title of this talk is, <a href="http://www.oscon.com/oscon2010/public/schedule/detail/13632">Dist::Zilla &#8211; Maximum Overkill for CPAN Distributions</a>.</p>
<p>Every CPAN distribution contains a significant amount of crap.  It&#8217;s infrastructure used for the distribution tools.</p>
<p><a href="http://search.cpan.org/dist/ExtUtils-MakeMaker/"><tt>ExtUtils::MakeMaker</tt></a> has been the traditional way to work on the infrastructure code.  By necessity, it contains a lot of legacy, which can be cumbersome to maintain.  Enter <a href="http://search.cpan.org/dist/ExtUtils-MakeMaker/"><tt>Module::Install</tt></a>, which can look in the expected places for the necessary information, such as the author name.  But, the author still must write all the boilerplate.  <a href="http://search.cpan.org/dist/ExtUtils-MakeMaker/"><tt>Module::Starter</tt></a> was written to address this, composing all the boilerplate on behalf of the author.  There is so much boilerplate that, by default, Module::Starter also provides a boilerplate test to detect it.</p>
<p>Why are we doing all of this?  How much repetitive work are we doing?</p>
<p>What can <a href="http://search.cpan.org/dist/Dist-Zilla/"><tt>Dist::Zilla</tt></a> do for us?  For starters, we can remove some files:</p>
<ul>
<li><tt>LICENSE</tt></li>
<li><tt>MANIFEST.SKIP</tt></li>
<li><tt>Makefile.PL</tt></li>
<li><tt>README</tt></li>
<li><tt>t/pod.t</tt></li>
<li><tt>t/pod-coverage.t</tt></li>
</ul>
<p>Leaving us with only our <tt>Changes</tt> file, our code, and our tests.  The non-infrastructure parts.  On top of that, <tt>Dist::Zilla</tt> does all of the boring distribution bits for us.  It only handles the <tt>make dist</tt> command.  It does not handle the <tt>make install</tt> command, which means the users who install the module don&#8217;t need all of the dependencies.</p>
<p><tt>Dist::Zilla</tt> puts all of its functionality into plugins, which will be the meat of the rest of this session.  It also uses a very simple INI-style configuration file.</p>
<p>The main command provided by the module is <tt>dzil build</tt>.  This bundles the distribution, which will contain all of the infrastructure necessary for users to install the module.  When building, it follows a simple work flow:</p>
<ol>
<li>Gather files</li>
<li>Munge files</li>
<li>Collect metadata</li>
<li>Write out</li>
</ol>
<p>There is no default configuration, but there is a <a href="http://search.cpan.org/perldoc?Dist::Zilla::PluginBundle::Basic">Basic plugin bundle</a> that will include all of the most common plugins.</p>
<p>What followed were examples of what the plugins can do.  Of course, all of them are designed to reduce cruft&mdash;the non-code, non-documentation bits that we&#8217;re forced to maintain.  The philosophy is the same one I advocate to anyone who will listen: computers are good at doing boring, repetitive tasks with derived data; why don&#8217;t we let them do more of that stuff?</p>
<p>I&#8217;ve followed <a href="http://twitter.com/rjbs">@rjbs</a> on Twitter for a while, and I&#8217;ve seen him talk about <tt>Dist::Zilla</tt>.  I&#8217;ve wanted to try it out for a while, to simplify my distributions&mdash;both for CPAN and for my day job&mdash;but I didn&#8217;t realize until this session just how awesome the tool is.  It&#8217;s a complete framework for managing Perl module distributions.  <tt>Dist::Zilla</tt> will give my <a href="http://c2.com/cgi/wiki?LazinessImpatienceHubris">Laziness</a> score a huge bump.</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/oscon-2010-distzilla/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

