Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Dist::Zilla::Plugin::PkgVersion vs. Perl::Critic and strictures

by FalseVinylShrub (Chaplain)
on Jun 22, 2010 at 05:45 UTC ( #845839=perlquestion: print w/ replies, xml ) Need Help??
FalseVinylShrub has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I've recently been trying to catch up and improve my Perl skills. That includes trying to get my code to pass perlcritic (with suitable configuration) and trying to use Dist::Zilla to automate builds. However I keep running into a problem:

PkgVersion adds a line setting $VERSION after each package line, saving the bother of updating these by hand and the probable inconsistencies caused by that.

However, Perl::Critic::(...)::RequireUseStrict will complain about the version setting code coming before use strict; in the module. (same applies for ...::RequireUseWarnings)

If I move use strict; use warnings; before the package statement, Perl::Critic::(...)::RequireExplicitPackage complains that I have code outside of an explicit package.

I would like to keep both of these policies to tell me about mistakes. However in this case the violations seem harmless, right?

I am also wondering, is there a reason to prefer one of

use strict; use warnings; package Foo; ...

versus

package Foo; use strict; use warnings; ...

Is one more helpful than the other?

My current thinking is that it will be best to modify Dist::Zilla::Plugin::PkgVersion to put the version number after strictures. However, this might be quite hard. So before I start, has anyone else solved this or got a suggestion for a better solution?

Thanks

FalseVinylShrub

Disclaimer: Please review and test code, and use at your own risk... If I answer a question, I would like to hear if and how you solved your problem.

Comment on Dist::Zilla::Plugin::PkgVersion vs. Perl::Critic and strictures
Select or Download Code
Re: Dist::Zilla::Plugin::PkgVersion vs. Perl::Critic and strictures
by rjbs (Pilgrim) on Jun 22, 2010 at 12:04 UTC
    I use:
    use strict; use warnings; package Foo;
    Then P:C would complain about code outside package, except that I also use Perl::Critic::Policy::Lax, which has a policy to work around that.
    rjbs

      Hi

      Cool. That was what I was looking for. Thanks.

      FalseVinylShrub

      Disclaimer: Please review and test code, and use at your own risk... If I answer a question, I would like to hear if and how you solved your problem.

Re: Dist::Zilla::Plugin::PkgVersion vs. Perl::Critic and strictures
by Herkum (Parson) on Jun 22, 2010 at 14:42 UTC

    If you are going to follow PBP then you should have only one package declaration per file. If you have one package per file, you really don't have a reason to declare strict and warnings outside of a package declaration.

    I guess the real question is how much are you willing to follow PBP, not only for your benefit but others as well. Remember, just because you understand your implementation of the PBP, does not mean the next person will.

      Hi

      Does PBP recommend putting pragmatism before packaging (or vice-versa)? It's a long time since I read it, and I don't have a copy available at the moment.

      I did install Module::Starter::PBP and the module has the form:

      package Foo; use warnings; use strict;

      But is there any disadvantage to doing things the other way round? I can't think of one, so I will stick with rjbs's suggestion unless someone can point one out.

      FalseVinylShrub

      Disclaimer: Please review and test code, and use at your own risk... If I answer a question, I would like to hear if and how you solved your problem.

Re: Dist::Zilla::Plugin::PkgVersion vs. Perl::Critic and strictures
by emazep (Priest) on Jan 21, 2011 at 11:28 UTC
    I had the same problem and I've solved it this way:
    ## no critic package My::Package; ## use critic use strict; use warnings;
    so that Dist::Zilla::Plugin::PkgVersion will expand it to:
    ## no critic package My::Package; BEGIN { $My::Package::VERSION = '1.23'; } ## use critic use strict; use warnings;
    and everyone is happy :-)
Re: Dist::Zilla::Plugin::PkgVersion vs. Perl::Critic and strictures
by voj (Acolyte) on Oct 21, 2013 at 12:40 UTC
    You can use [OurPkgVersion] instead of [PkgVersion] and explicitly tell where the version statement should be inserted in your code (after use strict).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://845839]
Approved by rovf
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2014-07-13 02:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (245 votes), past polls