<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Boilerplate irritates me. I dislike starting every script with
"use warnings; use strict" etc. So I came up with a module
Boilerplate.pm. I've thought about putting it on CPAN, but it
needs to change depending on the version of Perl you're using, and
everyone would want their own variant.</p>
<p>You can see what antique version of Perl I'm using .. this is
the "modern" replacement for what's currently running on 5.6.1 -
thanks Red Hat.</p>
<p>I probably shouldn't have utf8 in there, I don't think utf8
characters are going to get into stock & bond names, cusips,
isins, and this week we were warned of the errors that can arise
from combining utf8 & \d regex.</p>
<p>Since you mention PerlCritic, I used to create constants for
punctuation characters, since PerlCritic warns you about them. And
I do like the idea of defining constants at the top, rather than
littering punctuation throughout the code. Since I was
inconsistent about definition names, I wound up defining
punctuation and the IO modes here as well. I'm still hoping to
switch to a modern version of Perl, in which case there will be a
longer list of modules, some of them different ... oh, to enable
signatures and postderef!<br>
</p>
<p>package Boilerplate;</p>
<p>use warnings;<br>
use strict;<br>
use utf8;<br>
use 5.010;</p>
<p>use autodie;<br>
use Carp;<br>
use Data::Dumper;<br>
use English '-no_match_vars';<br>
use FindBin '$Bin';<br>
use File::Basename;<br>
</p>
<p># All the variables defined in English<br>
</p>
<p>my @PERL_VARS = qw( ACCUMULATOR ARG BASETIME CHILD_ERROR ...
WARNING );</p>
sub import {<br>
<br>
warnings->import();<br>
strict->import;<br>
feature->import(':5.010');<br>
<br>
autodie->import();<br>
English->import('-no_match_vars');<br>
FindBin->import('$Bin');<br>
<br>
our $PUNC = ( ampersand => q{&}, at => q{@}, backslash
=> q{\\}, <br>
... underscore => q{_} <br>
);<br>
our %IO = ( append => q{>>}, delreadwrite =>
q{>+}, pipe_from => q{-|}, pipe_to => q{|-}<br>
read => q{<}, readwrite =>
q{+<}, write => q{>}<br>
);<br>
<br>
my $caller = caller(0);<br>
<br>
do {<br>
no strict 'refs';<br>
*{"$caller\:\:Bin"} = *{"FindBin::Bin};<br>
# and similar for Dumper, IO, PUNC<br>
*{"$caller\:\:$_"} = *{"English\:\:$_"} for @PERL_VARS;<br>
}<br>
}<br>
<br>
I should probably have used *{"${caller}::Bin"} rather than escaping
the colons, but it didn't occur to me at the time.<br>
<br>
<div class="moz-cite-prefix">On 2017-05-04 08:24 PM, Harold Tessmann
wrote:<br>
</div>
<blockquote
cite="mid:CAO=o5E2qOYAe6ux_PnjL3o2XyY-Kag5evk3-oOz2AZ-5A3ojBQ@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>Hi from Michigan! Apologies if that’s a little far away for
the Toronto list, but the local <a moz-do-not-send="true"
href="http://pm.org">pm.org</a> mailing lists seems a little
dead.</div>
<div><br>
</div>
<div>I'm looking to productionize some Perl scripts, and as
such, I want to adopt more structure than I use in disposable
scripts. These scripts would be used within the bounds of my
employer, not released to the general public (with maybe one
or two exceptions). I know that TIMTOWTDI, but I like the
“sometimes consistency is not a bad thing either” extension
when it comes to common problems such as command-line option
parsing, and the perldocs don’t go in depth on what people use
in the real world. I’m looking for advice on topics including,
but not limited to:</div>
<div><br>
</div>
<div>• Modern Perl: I like it in general, and I can install it
on my team’s machines. Are there reasons I shouldn’t use it?</div>
<div><br>
</div>
<div>• Does anybody have a suggestion for a good blank script
template? For instance, I know I want "use Modern::Perl
'version';" or "use warnings/strict;", etc., but there’s
probably other things I would want in a basic script. I’ve
handled this in a sort of ad-hoc manner, growing new scripts
based on what I learned from the old, but I’d like to build a
good template once and be done with it. I’d also like the
template to include documentation, and that raises more
questions. Is there a reason to put my pod block near the top
vs. the bottom? Getopt::Tiny seems nice, including a feature
to automagically build a usage block—should I use that or is
there a reason to avoid it? Or is there a better option
parser?</div>
<div><br>
</div>
<div>• Do you run Perl::Critic on your code? I know I’ll disable
some of the rules, but is it more hassle overall than it’s
worth? Similarly, PerlTidy: it seems useful for generating
HTML versions of documentation, but I write code in a very
precise way, such it would take more time to configure it than
I would save in reformatting.</div>
<div><br>
</div>
<div>• Thus far I haven’t built anything complicated enough to
warrant figuring out an object library; I can get by with
basic hash-based structures. I’ve read a bit about Moose and
Dancer: how do they compare? And what else is widely-used that
I should consider?</div>
<div><br>
</div>
<div>Any advice is greatly appreciated.</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Harold</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
toronto-pm mailing list
<a class="moz-txt-link-abbreviated" href="mailto:toronto-pm@pm.org">toronto-pm@pm.org</a>
<a class="moz-txt-link-freetext" href="http://mail.pm.org/mailman/listinfo/toronto-pm">http://mail.pm.org/mailman/listinfo/toronto-pm</a>
</pre>
</blockquote>
<br>
</body>
</html>