Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the SVN-Hooks CPAN distribution.

Report information
The Basics
Id: 66281
Status: rejected
Priority: 0/
Queue: SVN-Hooks

People
Owner: GNUSTAVO [...] cpan.org
Requestors: cscm [...] csquad.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: SVN::Hooks::PerlCritic
Hi Gustavo, As I use SVN::Hooks at work, i've started to write a small plugin for Perl::Critic. Now You can use perlcritic as an hook for post and pre-commits. CHECK_PERLCRITIC_PRE_COMMIT(-severity => 'stern' ); CHECK_PERLCRITIC_POST_COMMIT(-severity => 'brutal', -theme => 'bugs'); Would you like to include this hook in the SVN::Hooks distribution? Is the code clean enough and well documented? Best Regards,
Subject: PerlCritic.pm
package SVN::Hooks::PerlCritic; use strict; use warnings; use Carp; use SVN::Hooks; use SVN::Notify; use Perl::Critic; use Exporter qw/import/; our @EXPORT = qw/CHECK_PERLCRITIC_PRE_COMMIT CHECK_PERLCRITIC_POST_COMMIT/; our $VERSION = $SVN::Hooks::VERSION; =head1 NAME SVN::Hooks::PerlCritic - Check files with Perl::Critic in commits. =head1 SYNOPSIS This SVN::Hooks plugin allows one to check if the files in a 'svn commit' conforms to Perl::Critic Policy. It's configured by the following directive. =head2 CHECK_PERLCRITIC_PRE_COMMIT({OPT => VALUE, ...}) It's active in the C<pre-commit> hook. =head2 CHECK_PERLCRITIC_POST_COMMIT({OPT => VALUE, ...}) It's active in the C<post-commit> hook. The available options are the following: =over =item B<-profile> is a path to a configuration file. =item B<-severity> is the minimum severity level. =item B<-theme> is special expression that determines which Policies to apply based on their respective themes. =item B<-include> is a reference to a list of string @PATTERNS. =item B<-exclude> is a reference to a list of string @PATTERNS. =item B<-single-policy> is a string PATTERN. Only one policy that matches m/$PATTERN/ixms will be used. =item B<-force> is a boolean value that controls whether Perl::Critic observes the magical "## no critic" =item B<-verbose> can be a positive integer (from 1 to 11), or a literal format specification. =back See L<Perl::Critic> for further explanation. CHECK_PERLCRITIC_PRE_COMMIT( -severity => 'stern', -theme => 'bugs' ); CHECK_PERLCRITIC_POST_COMMIT( -severity => 'brutal', -theme => 'bugs' ); CHECK_PERLCRITIC_POST_COMMIT( -severity => 'brutal', -verbose => 11 ); =cut sub CHECK_PERLCRITIC_PRE_COMMIT { my (%opts) = @_; my $conf = $SVN::Hooks::Confs->{CHECK_PERLCRITIC_PRE_COMMIT}; $conf->{"opts"} = \%opts; $conf->{'pre-commit'} = \&hook; return 1; } sub CHECK_PERLCRITIC_POST_COMMIT { my (%opts) = @_; my $conf = $SVN::Hooks::Confs->{CHECK_PERLCRITIC_POST_COMMIT}; $conf->{"opts"} = \%opts; $conf->{'post-commit'} = \&hook; return 1; } $SVN::Hooks::Inits{CHECK_PERLCRITIC_PRE_COMMIT} = sub { return {} }; $SVN::Hooks::Inits{CHECK_PERLCRITIC_POST_COMMIT} = sub { return {} }; sub hook { my ($self, $svnlook) = @_; my $critic = Perl::Critic->new(%{$self->{opts}}); my @errors; foreach my $modified ($svnlook->added(), $svnlook->updated()) { next if $modified =~ m:/$:; # disregard directories next if $modified !~ m/\.p(l|m)/; # match only perl source code my $content = $svnlook->cat($modified); my @violations = $critic->critique(\$content); foreach my $violation (@violations) { push @errors, "$modified: ".$violation->to_string(); } } if (@errors) { my $message = "PERL CRITIC\n" . join("", @errors); croak $message; } return; } =head1 AUTHOR Christophe Nowicki, C<< <cscm@csquad.org> >> =head1 BUGS Please report any bugs or feature requests to C<bug-svn-hooks-checkproperty at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SVN-Hooks>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc SVN::Hooks You can also look for information at: =over 4 =item * RT: CPAN's request tracker L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SVN-Hooks> =item * AnnoCPAN: Annotated CPAN documentation L<http://annocpan.org/dist/SVN-Hooks> =item * CPAN Ratings L<http://cpanratings.perl.org/d/SVN-Hooks> =item * Search CPAN L<http://search.cpan.org/dist/SVN-Hooks> =back =head1 COPYRIGHT & LICENSE Copyright 2008-2009 CPqD, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of SVN::Hooks::PerlCritic
Subject: Re: [rt.cpan.org #66281] SVN::Hooks::PerlCritic
Date: Sat, 5 Mar 2011 21:32:10 -0300
To: bug-SVN-Hooks [...] rt.cpan.org
From: Gustavo Leite de Mendonça Chaves <gnustavo [...] cpan.org>
2011/3/1 http://id.csquad.org/identity/cscm via RT < bug-SVN-Hooks@rt.cpan.org> Show quoted text
> Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=66281 > > > Hi Gustavo, > > As I use SVN::Hooks at work, i've started to write a small plugin for > Perl::Critic. Now You can use perlcritic as an hook for post and > pre-commits. > > CHECK_PERLCRITIC_PRE_COMMIT(-severity => 'stern' ); > CHECK_PERLCRITIC_POST_COMMIT(-severity => 'brutal', -theme => 'bugs'); > > Would you like to include this hook in the SVN::Hooks distribution? > > Is the code clean enough and well documented? >
Bon soir, Christophe. I'd like to make very few changes in your code to include it in the SVN::Hooks distribution. It's good and clean. However, since I included the Generic plugin it became easier to include new functionality in the distribution. For instance, your hook could be included like this: my $critic = Perl::Critic->new(%opts); sub perl_critic { my ($svnlook) = @_; my @errors; foreach my $modified ($svnlook->added(), $svnlook->updated()) { next if $modified !~ m/\.p[lm]$/; # match only perl source code my $content = $svnlook->cat($modified); my @violations = $critic->critique(\$content); foreach my $violation (@violations) { push @errors, "$modified: ".$violation->to_string(); } } die "PERL CRITIC\n" . join("", @errors) if @errors; return; } GENERIC('pre-commit' => \&perl_critic); There's no need to create a whole new plugin to make the funcionatily available now. In fact, I intend to deprecate some of the plugins and turn them into a library of code that utilizes the GENERIC plugin to make them available. So, I thank you very much for your contribution. I'll hold it for later, when I get a chance to refactor the distribution in this new fashion, I'd like to include it as a generic hook. Ah, I think that your hook is perfect for a pre-commit, but it wouldn't work as a post-commit, becase then the commit would be done and you wouldn't be able to see the problem. Regards. Gustavo.
This could be better implemented using the Generic hook.