The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<html><head><title>sanity</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
</head>
<body class='pod'>
<!--
  generated by Pod::Simple::HTML v3.28,
  using Pod::Simple::PullParser v3.28,
  under Perl v5.014002 at Thu Oct  2 03:45:37 2014 GMT.

 If you want to change this HTML document, you probably shouldn't do that
   by changing it directly.  Instead, see about changing the calling options
   to Pod::Simple::HTML, and/or subclassing Pod::Simple::HTML,
   then reconverting this document from the Pod source.
   When in doubt, email the author of Pod::Simple::HTML for advice.
   See 'perldoc Pod::Simple::HTML' for more info.

-->

<!-- start doc -->
<a name='___top' class='dummyTopAnchor' ></a>

<h1><a class='u'
name="NAME"
>NAME</a></h1>

<p>sanity - The ONLY meta pragma you&#39;ll ever need!</p>

<h1><a class='u'
name="SYNOPSIS"
>SYNOPSIS</a></h1>

<pre>   use sanity;
   use sanity &#39;strictures&#39;;
   use sanity &#39;Modern::Perl&#39;;

   use sanity qw(
      strictures -warnings/uninitialized/FATAL
      NO:autovivification NO:autovivification/store
      PRINT_PRAGMA_HASH
   );
   use sanity &#39;!0*b^Npow{8T7_yZt&#60;?cT6/?ZCO=Y0LV_Duoc&#39;;  # Safer ASCII version
   use sanity &#39;&#161;0&#498;&#40262;&#14631;&#48222;&#10347;&#30225;&#48760;&#4757;&#46152;&#45868;&#22173;&#10280;&#33281;&#32892;&#19339;&#39;;  # Shorter UTF8 version</pre>

<h1><a class='u'
name="DESCRIPTION"
>DESCRIPTION</a></h1>

<p>Modern::Perl? common::sense? no nonsense? use latest?</p>

<p>Everybody has their own opinion on what pragmas and modules are &#34;required&#34; for every person to use. These opinions turn into &#34;personal pragmas&#34;, so that people don&#39;t have to type several <code>use</code> lines of header in front of every module they write.</p>

<p>Personal opinions and pragmas don&#39;t really belong in the CPAN namespace. (It&#39;s CPAN, not Personal PAN. If you want a Personal PAN, go call Pizza Hut.) But copying code on potentially hundreds of modules doesn&#39;t make sense, either.</p>

<p>That was my mentality when I had a personal opinion of my own. Why repeat the same problem like everybody else?</p>

<p>This &#34;sanity&#34; module attempts to level the playing field by making it a <b>customizable</b> personal pragma, allowing you to both reduce the code needed and still implement all of the modules/pragmas you need.</p>

<p>As an illustration to what it&#39;s capable of, this pragma will emulate all of the other personal pragmas, most of them 100% working exactly how they do it.</p>

<h1><a class='u'
name="PARAMETERS"
>PARAMETERS</a></h1>

<p>Sanity&#39;s parameters fall into three types: flags, aliases, and hashes. (Oh my!)</p>

<h2><a class='u'
name="Flags_and_Aliases"
>Flags and Aliases</a></h2>

<p>Flags are single pragma/module declarations, strict/warning flags, or other items that need flags. Aliases are merely one or more flags, grouped together to better emulate the pragma/module&#39;s functionality.</p>

<p>Let&#39;s start off with an example:</p>

<pre>   # These three statements do the same thing as...
   use Modern::Perl;
   use sanity &#39;Modern::Perl&#39;;
   use sanity qw(strict warnings mro/dfs feature IO::File IO::Handle);

   # ...these statements
   use strict;
   use warnings;
   use mro &#39;dfs&#39;;
   use feature &#39;:all&#39;;
   use IO::File;
   use IO::Handle;</pre>

<p>Basically, it does the same thing as the meta pragma <a href="http://search.cpan.org/perldoc?Modern%3A%3APerl" class="podlinkpod"
>Modern::Perl</a>, except you actually don&#39;t need that module for it to work. While there is some magic to make sure, say, <code>feature</code> gets loaded with various versions of Perl, it typically just works using a standard <code>import</code> call. The <code>strict</code> and <code>warnings</code> flags are combined aliases that enable all of the warnings that they would do via a standard call.</p>

<h3><a class='u'
name="Negating_flags/aliases"
>Negating flags/aliases</a></h3>

<p>You can turn off flags in the statement:</p>

<pre>   use sanity qw(Modern::Perl -mro/dfs);</pre>

<p>This does the same thing as above, except it doesn&#39;t import the <code>mro</code> pragma. You can negate any flag, including combined aliases, as long as it makes sense. In other words, you need a positive included before you can negate something.</p>

<h3><a class='u'
name="NO:*_flags/aliases"
>NO:* flags/aliases</a></h3>

<p>Some pragmas work by using the <code><b>unimport</b></code> function, so that the English makes sense. To keep that syntax, these pragmas are included with a <code>NO:</code> prefix:</p>

<pre>   use sanity &#39;NO:multidimensional&#39;;
   use sanity &#39;NO:indirect/FATAL&#39;;</pre>

<p>This will run the <code>unimport</code> function on these pragmas, even though sanity was called via the <code>import</code> function (via <code>use</code>).</p>

<h3><a class='u'
name="Perl_versions"
>Perl versions</a></h3>

<p>Sanity also supports Perl versions as a special kind of alias to specify minimum Perl versions:</p>

<pre>   # These are all the same:
   use v5.10.1;
   use sanity &#39;v5.10.1&#39;;
   use sanity v5.10.1;  # as a VSTRING
   use sanity 5.10.1;   # works too

   # Upgrade the Perl version of your favorite pragma
   use sanity qw(NO:nonsense v5.12);</pre>

<p>Note that the version must be at least v5.8. This should be fine for most people. (If I get a ticket requesting support for a Perl version older than one released in 2002, I will hunt you down and break your keyboard in half.)</p>

<h3><a class='u'
name="The_Default"
>The Default</a></h3>

<p>What does <code>sanity</code> do without any parameters? Why my personal preference, of course :) It&#39;s listed in the <code>meta pragma</code> section of the <a href="#LIST_OF_FLAGS" class="podlinkpod"
>&#34;LIST OF FLAGS&#34;</a> below. I detail the reasons behind my choices <a href="http://search.cpan.org/perldoc?sanity%3A%3Asanity" class="podlinkpod"
>here</a>.</p>

<h2><a class='u'
name="Hashes"
>Hashes</a></h2>

<p>So, there&#39;s all of these flags, but unless you&#39;re using one of the combined aliases, typing them all out is usually just as much (or more) code as the several lines of <code>use</code> statements. Well, they are all flags so that it fits into a giant bitmap, and that bitmap can be compressed into a large ASCII (or UTF-8) &#34;number&#34;.</p>

<p>This number can be calculated using the flag <code>PRINT_PRAGMA_HASH</code>:</p>

<pre>   # This is merely the definition of uni::perl
   use sanity (qw(
      v5.10 strict feature/5.10
   ), (
      map { &#34;warnings/$_/FATAL&#34; } qw(closed threads internal debugging pack substr malloc
      unopened portable prototype inplace io pipe unpack regexp deprecated exiting glob
      digit printf utf8 layer reserved parenthesis taint closure semicolon)
   ), qw(
      -warnings/exec/FATAL
      -warnings/newline/FATAL
      utf8
      open/utf8
      open/std
      mro/c3
      Carp
   ), &#39;PRINT_PRAGMA_HASH&#39;);

   # Outputs:
   # use sanity &#39;!04[D{9Fhfqc-7m738S4HK6B#D5=v{,T$(0)F5i&#39;;  # Safer ASCII version
   # use sanity &#39;&#161;05&#3861;&#4689;&#37353;&#33116;&#51576;&#48433;&#26951;&#17421;&#53733;&#29088;&#8111;&#32251;&#35131;&#30495;&#22569;&#39;;  # Shorter UTF8 version</pre>

<p>You can use that hash as the output illustrates without having to type out the entire big set of commands or flags.</p>

<h2><a class='u'
name="Other_Meta_Pragmas"
>Other Meta Pragmas</a></h2>

<p>Have your own set that is too long, and you don&#39;t like the ugliness of the hash? Send me your suggestion and I&#39;ll probably add it in.</p>

<h1><a class='u'
name="CAVEATS"
>CAVEATS</a></h1>

<h2><a class='u'
name="&#39;NO:&#39;_ne_&#39;-&#39;"
>&#39;NO:&#39; ne &#39;-&#39;</a></h2>

<p>A <code>NO:</code> flag is NOT the same as negating a flag! You also cannot remove the <code>NO:</code> from a flag, as it&#39;s part of the name of the flag, not a special modifier.</p>

<pre>   # These two are NOT the same!
   use sanity &#39;NO:indirect&#39;;  # runs indirect-&#62;unimport()
   use sanity &#39;-indirect&#39;;    # Dies, as there is no such flag/alias

   # This runs through the strictures alias and runs autovivification-&#62;unimport()
   use sanity qw(strictures NO:autovivification);

   # This runs through the strictures alias WITHOUT running indirect-&#62;unimport()
   use sanity qw(strictures -NO:indirect);

   use sanity &#39;-indirect&#39;;    # This isn&#39;t what you want...
   no  sanity &#39;NO:indirect&#39;;  # ...you really meant to do this...
   use indirect;              # ...but this is better</pre>

<h2><a class='u'
name="Special_clearing_of_strict/warnings"
>Special clearing of strict/warnings</a></h2>

<p>Since most people want exactly the strictness and warnings they specify, sanity will clear these out first before running through the list.</p>

<pre>   # This...
   use sanity qw(strict -strict/vars);

   # ...is the same as this...
   no strict;
   use strict qw(subs refs);</pre>

<p>Also, some special magic is in place to ensure that newer warnings/features aren&#39;t fatal to older Perls. See <a href="https://rt.perl.org/rt3/Ticket/Display.html?id=112920" class="podlinkurl"
>https://rt.perl.org/rt3/Ticket/Display.html?id=112920</a>.</p>

<h2><a class='u'
name="&#34;Author&#34;_pragmas"
>&#34;Author&#34; pragmas</a></h2>

<p>Certain pragmas really only exist to make sure the code is designed right. These pragmas are deemed &#34;optional&#34; by <code>sanity</code>. In other words, if the user doesn&#39;t have them, it will just silently ignore them and move on. If <code>sanity</code> thinks you&#39;re an author/coder of the module itself (.git/svn/$ENV checks), it will give you a warning that they are missing, but move on.</p>

<p>The following modules don&#39;t &#34;instadie&#34;. Modules that fall under this list don&#39;t change the nature of how Perl works, or would let you do something that would normally fatally error.</p>

<pre>   overloading
   autovivification
   indirect
   multidimensional
   bareword::filehandles
   criticism

   # (autovivification probably shouldn&#39;t be here, since it actually
   # prevents autoviv, but it&#39;s generally used as an author tool.)</pre>

<p>This feature was borrowed from <a href="http://search.cpan.org/perldoc?strictures" class="podlinkpod"
>strictures</a> and tweaked.</p>

<h1><a class='u'
name="LIST_OF_FLAGS"
>LIST OF FLAGS</a></h1>

<h2><a class='u'
name="Emulation_of_&#34;meta_pragmas&#34;"
>Emulation of &#34;meta pragmas&#34;</a></h2>

<pre>   ex::caution:
      strict
      warnings
   NO:crap:  # Same as above
   shit:     # Same as above
   latest:
      strict
      warnings
      feature
   sane:
      strict
      warnings
      feature
      utf8
   NO:nonsense:
      strict
      warnings
      true
      namespace::autoclean
   Modern::Perl:
      strict
      warnings
      mro &#39;dfs&#39;
      feature
      IO::File
      IO::Handle
   strictures: (without the 5.8.4 checks; that crap is old)
      v5.8.4 (forced, to make sure things work)
      strict
      warnings FATAL =&#62; &#39;all&#39;
      no indirect &#39;fatal&#39;
      no multidimensional
      no bareword::filehandles
   common::sense: (without the &#34;memory usage&#34; BS)
      utf8
      strict qw(subs vars)
      feature qw(say state switch)
      no warnings
      warnings FATAL =&#62; qw(closed threads internal debugging pack malloc portable prototype
                           inplace io pipe unpack deprecated glob digit printf
                           layer reserved taint closure semicolon)
      no warnings qw(exec newline unopened);
   uni::perl: (ditto)
      v5.10
      strict
      feature qw(say state switch)
      no warnings
      warnings qw(FATAL closed threads internal debugging pack substr malloc
                      unopened portable prototype inplace io pipe unpack regexp
                      deprecated exiting glob digit printf utf8 layer
                      reserved parenthesis taint closure semicolon)
      no warnings qw(exec newline)
      utf8
      open (:utf8 :std)
      mro &#39;c3&#39;
      Carp
   sanity:
      v5.10.1
      utf8
      open (:utf8 :std)
      mro &#39;c3&#39;
      strict qw(subs vars)
      no strict &#39;refs&#39;
      warnings FATAL =&#62; &#39;all&#39;
      no warnings qw(uninitialized experimental::smartmatch)
      feature &#39;5.10&#39;
      no autovivification qw(fetch exists delete store strict)
      no indirect &#39;fatal&#39;
      no multidimensional
   perl5i::0 / 1 / 2 / latest:
      [the real module] (the pragma is too insane to try to duplicate here)
   Acme::Very::Modern::Perl:  (a joke, but it&#39;s still here all the same)
      strict
      warnings
      mro &#39;c3&#39;
      feature
      IO::File
      IO::Handle
      utf8
      open (:utf8 :std)
      no warnings
      warnings FATAL =&#62; qw(closed threads internal debugging pack malloc portable prototype
                           inplace io pipe unpack deprecated glob digit printf
                           layer reserved taint closure semicolon)
      no warnings qw(exec newline unopened);
      perl5i::latest
      Toolkit
      Carp</pre>

<h2><a class='u'
name="Other_flags/aliases"
>Other flags/aliases</a></h2>

<pre>   strict/* =&#62; strict &#39;[whatever]&#39;        # supports all flags
   strict   =&#62; strict qw(refs subs vars)

   # other &#34;hints&#34;
   integer
   locale
   bytes
   re/taint
   re/eval
   filetest
   utf8
   NO:overloading

   warnings/*       =&#62; warnings NONFATAL =&#62; &#39;[whatever]&#39;  # supports all flags, multi or not
   warnings/*/FATAL =&#62; warnings    FATAL =&#62; &#39;[whatever]&#39;  # supports all flags; FATAL trumps NONFATAL
   warnings         =&#62; warnings NONFATAL =&#62; &#39;all&#39;
   warnings/FATAL   =&#62; warnings    FATAL =&#62; &#39;all&#39;

   feature/*        =&#62; feature &#39;[whatever]&#39;  # supports all flags
   feature/5.##     =&#62; # similar to feature enabling via &#39;use v5.##&#39;; major version only
   feature/5.9.5    =&#62; # also exists, just like feature/5.10
   feature          =&#62; feature &#39;:all&#39;  # not exactly, but in spirit

   # Perl versions, described above
   v5.##.##

   # autodie
   autodie/* =&#62; autodie &#39;:[whatever]&#39;  # supports all _category_ flags, like all, io, shm, etc.
                                       # (Will expand if requested, but I don&#39;t want to waste
                                       # all of that bit space right now.)
   autodie   =&#62; autodie &#39;:default&#39;

   # other CORE pragmas
   bigint
   bignum
   bigrat
   charnames
   charnames/short
   charnames/full
   encoding::warnings
   encoding::warnings/FATAL
   mro/dfs                    # default for &#39;mro&#39;
   mro/c3
   open/*

   # namespace cleaners
   namespace::clean       # included last; adds -except =&#62; &#39;meta&#39;
   namespace::functions   # included last
   namespace::autoclean
   namespace::sweep

   # others
   NO:autovivification/*
   NO:autovivification =&#62; no autovivification qw(fetch exists delete)

   criticism/*
   criticism   =&#62; criticism &#39;gentle&#39;

   experimental/*

   perl5i::0
   perl5i::1
   perl5i::2
   perl5i::3
   perl5i::latest

   NO:indirect
   NO:indirect/global
   NO:indirect/fatal
   NO:multidimensional
   NO:bareword::filehandles

   subs::auto
   utf8::all
   IO::File
   IO::Handle
   IO::All
   Carp
   vendorlib
   true
   autolocale
   Toolkit

   Function::Parameters
   Function::Parameters/strict
   Switch::Plain
   Quote::Code</pre>

<p>Am I missing something? Let me know.</p>

<h1><a class='u'
name="TODO"
>TODO</a></h1>

<p>Actually need to write sanity::sanity POD.</p>

<h1><a class='u'
name="AVAILABILITY"
>AVAILABILITY</a></h1>

<p>The project homepage is <a href="https://github.com/SineSwiper/sanity" class="podlinkurl"
>https://github.com/SineSwiper/sanity</a>.</p>

<p>The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit <a href="http://www.perl.com/CPAN/" class="podlinkurl"
>http://www.perl.com/CPAN/</a> to find a CPAN site near you, or see <a href="https://metacpan.org/module/sanity/" class="podlinkurl"
>https://metacpan.org/module/sanity/</a>.</p>

<h1><a class='u'
name="SUPPORT"
>SUPPORT</a></h1>

<h2><a class='u'
name="Internet_Relay_Chat"
>Internet Relay Chat</a></h2>

<p>You can get live help by using IRC ( Internet Relay Chat ). If you don&#39;t know what IRC is, please read this excellent guide: <a href="http://en.wikipedia.org/wiki/Internet_Relay_Chat" class="podlinkurl"
>http://en.wikipedia.org/wiki/Internet_Relay_Chat</a>. Please be courteous and patient when talking to us, as we might be busy or sleeping! You can join those networks/channels and get help:</p>

<ul>
<li>irc.perl.org
<p>You can connect to the server at &#39;irc.perl.org&#39; and talk to this person for help: SineSwiper.</p>
</li>
</ul>

<h2><a class='u'
name="Bugs_/_Feature_Requests"
>Bugs / Feature Requests</a></h2>

<p>Please report any bugs or feature requests via <a href="https://github.com/SineSwiper/sanity/issues" class="podlinkurl"
>https://github.com/SineSwiper/sanity/issues</a>.</p>

<h1><a class='u'
name="AUTHOR"
>AUTHOR</a></h1>

<p>Brendan Byrd &#60;BBYRD@CPAN.org&#62;</p>

<h1><a class='u'
name="CONTRIBUTOR"
>CONTRIBUTOR</a></h1>

<p>Graham Knop &#60;haarg@haarg.org&#62;</p>

<h1><a class='u'
name="COPYRIGHT_AND_LICENSE"
>COPYRIGHT AND LICENSE</a></h1>

<p>This software is Copyright (c) 2014 by Brendan Byrd.</p>

<p>This is free software, licensed under:</p>

<pre>  The Artistic License 2.0 (GPL Compatible)</pre>

<!-- end doc -->

</body></html>