Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 15101
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: thaljef [...] cpan.org
Requestors: chris+rt [...] chrisdolan.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.12
Fixed in: 0.13_01



Subject: Make third-party Policy plugins easier
Right now adding a new Policy module requires either a new entry in a perlcriticrc file, or a change to Perl::Critic::Config to change the default list of policies. The former is a pain if you have a lot or perlcriticrc files (e.g. I use one per CPAN module for Test::Perl::Critic in */t/perlcriticrc). And the latter is clearly not feasible for third parties. I propose these changes to simplify adding new policies: * Use Module::Pluggable to automatically collect the list of all installed policies * Make every policy know its own default priority number - Add a function to the policy that returns its priority - Optionally omit the function for a priority of 1 * Populate the Perl::Critic::Config::default_config dynamically using the above (or remove the default_config concept entirely) With those changes, third parties can release Perl-Critic-Policy-Foo to CPAN. Simply installing that package then automatically activates the Foo policy. Users can subsequently disable it or change its priority as usual. Using Module::Pluggable could simply Perl::Critic::new() and Perl::Critic::add_policy. Here's the important line of the implementation: use Module::Pluggable search_path => ['Perl::Critic::Policy'], require => 1; The "require => 1" removes the need for most of the add_policy code. The addition of the Perl::Critic::Policy:: prefix should happen in the Config instead of in add_policy, IMO. -- Chris
That's a pretty cool idea. I'm not sure how it will work with modules like CodeLayout::RequireTidyCode, which are included in the distribution but aren't part of the default config. I definitely want to try it out though.
[THALJEF - Mon Oct 17 15:38:55 2005]: Show quoted text
> That's a pretty cool idea. I'm not sure how it will work with modules > like CodeLayout::RequireTidyCode, which are included in the > distribution > but aren't part of the default config. I definitely want to try it > out > though.
That one could simply have a sub like this: sub priority { return 5; } and Config says (in pseudo-code) for my $policy (...) { my $priority = $cfg->{$policy}->{priority} || $policy->priority(); if ($priority <= $self->{priority}) } As long as Policy.pm has sub priority { return 1; } you only need to tweak the non-default policy modules.