Dist::Zilla strictures tip

So, mst wrote up strictures which basically bundles the "Kensho" pragmas, so to speak: strict, warnings (FATAL!), no indirect (vpit++). It plans for clean separation of different versions so you can maintain compatibility using specific versions of the pragma. How nifty is that? That's right, very nifty!

I'm using Dist::Zilla with Dist::Zilla::Plugin::CriticTests and Dist::Zilla::Plugin::PkgVersion. These are plugins that add Perl::Critic tests to my distribution and add a $VERSION variable automatically when building, respectively.

Now two problems occur:
1. Perl::Critic doesn't know about strictures and basically thinks I don't have "strict" on.
2. Since I'm using PkgVersion, I don't have to put a $VERSION variable. PkgVersion puts one right below the package declaration. This means that some code is written before my strictures.

Both are very easy to fix.

For the first one, I just add this to ~/.perlcriticrc:

equivalent_modules = strictures

Voila! Now Perl::Critic known that "strictures" is basically as good as "strict" for any testing purposes.

The second one is merely putting the strictures usage as the 1st line, before the package declaration:

use strictures 1;
package My::Kickass::Module;

Voici! Now strictures is added before the injected $VERSION variable PkgVersion adds.

Check out:

1 Comment

About problem n.2 (and it's solution), Perl::Critic::Policy::Modules::RequireExplicitPackage could complain because of the code outside of an explicit package.

I therefore prefer to do so:

## no critic
package My::Package;
## use critic
use strict;
use warnings;

which will be expanded by Dist::Zilla::Plugin::PkgVersion to:

## no critic
package My::Package;
$My::Package::VERSION = '1.23';
## use critic
use strict;
use warnings;

which seems to make everyone happy :-)

Leave a comment

About Sawyer X

user-pic Gots to do the bloggingz