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