Dear Monks,

A few weeks ago I wrote subversion hook-script that checks Perl code using Perl::Critic module --- perlcritic-checker.pl If the code has violations then the entire commit will be rejected. The appropriate error message (colored and sorted by severity level) will be sent back to the client. This way you can employ consistent coding rules in your team.

The script can be configured to apply different Perl::Critic policy profiles for different paths in the repository. For example, you can be very strict with brand new projects, make an indulgence for legacy projects and completely disable Perl::Critic for auto-generated and third-party code.

The code and configuration file examples can be downloaded from http://entropyware.info/perlcritic/perlcritic-checker.tar.gz

I appreciate any feedback from you guys!
  • Comment on Using Perl::Critic in Subversion hook script

Replies are listed 'Best First'.
Re: Using Perl::Critic in Subversion hook script
by Anonymous Monk on Dec 01, 2009 at 08:23 UTC
    Looks useful and tidy :)

    I would

    • pod2text perlcritic-checker.pl > README
    • code a short test.pl that
      • set up temp dir, test repo
      • add good file
      • add bad file
      • cleanup temp
    • maybe run through scriptdist, add File::ShareDir/Test::XT, add --install-defaults=path/to/repository, and put it on cpan :)
      Thanks for your idea!

      I've eventually released perlcritic-checker v1.2

      New features:
      • progressive mode (for legacy projects)
      • emergency commits (svn ci -m "NO CRITIC: emergency bugfix")
      • test suite

      Project's home page: http://code.google.com/p/perlcritic-checker/

      Also on CPAN: http://search.cpan.org/dist/perlcritic-checker/

Don't do this.
by elliot (Novice) on Feb 17, 2010 at 02:41 UTC
    As one of the Perl::Critic developers, I say don't do this. This is a Bad Idea. My hard drive is going down and I want to commit just to back up and you're going to block me from doing it? Source control is there to save your state; if the state is bad, you can always go back a revision. More here.

      I agree that there are situations when you *do* need to commit changes. That's why I've added new feature to the perlcritic-checker: emergency commits. The idea is very simple: when you are in a hurry, just place "magic" prefix in the beginning of the commit log message, e.g.:

      svn ci -m "NO CRITIC: I am in hurry" FooBar.pm

      This commit will bypass all checks. This code is not released yet, but I am in process of doing it.

      I've also implemented so-called "progressive mode" just like in Test::Perl::Critic::Progressive module but without history files. Current commit is compared to the previous one on the fly. This way perlcritic-checker doesn't complain about existing violations but prevents introducing new ones.

Re: Using Perl::Critic in Subversion hook script
by danb (Friar) on Dec 01, 2009 at 22:31 UTC
    What is a "Subversion"? Is that the VCS that my Grandpa used back in the stone ages before distributed version control? If so, I applaud your effort in understanding ancient systems and supporting the primitive software of last century. I wonder what this hook would look like if it were developed for more useful software, like Git?

    ;) j/k of course. I have to use svn a lot, but not by choice. :)