[libcode-tidyall-perl] 303/374: Allow a plugin to be listed multiple times in config with different configuration
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:26:40 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libcode-tidyall-perl.
commit 18b5289f347b292c7c6469ccf25d2936507c975e
Author: Jonathan Swartz <swartz at pobox.com>
Date: Wed Oct 3 16:39:04 2012 -0700
Allow a plugin to be listed multiple times in config with different configuration
---
Changes | 1 +
bin/tidyall | 19 ++++++++++++++++++-
lib/Code/TidyAll.pm | 11 ++++++++---
lib/Code/TidyAll/t/Basic.pm | 20 ++++++++++++++++++++
4 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/Changes b/Changes
index 5361211..c99059d 100644
--- a/Changes
+++ b/Changes
@@ -5,6 +5,7 @@ Revision history for Code-TidyAll
0.14 Sep 30, 2012
* Improvements
+ - Allow a plugin to be listed multiple times in config with different configuration
- Add -r/--recursive flag to process directories recursively
- In -p/--pipe mode, mirror input to output in case of error (Justin Devuyst)
- Add --version option
diff --git a/bin/tidyall b/bin/tidyall
index 41b3a73..6763d4f 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -342,7 +342,7 @@ Apply C<PodTidy> with default settings to all *.pm and *.pod files underneath
=over
-=item [class]
+=item [class] or [class description]
The header of each section refers to a tidyall I<plugin>. The name is
automatically prefixed with C<Code::TidyAll::Plugin::> unless it begins with a
@@ -356,6 +356,23 @@ automatically prefixed with C<Code::TidyAll::Plugin::> unless it begins with a
;
[+My::TidyAll::Plugin]
+You can also include an optional description after the class. The description
+will be ignored and only the first word will be used for the plugin. This
+allows you to a list a plugin more than once, with different configuration each
+time. For example, two different C<PerlCritic> configurations:
+
+ ; Be brtual on libraries
+ ;
+ [PerlCritic strict]
+ select = lib/**/*.pm
+ argv = --brutal
+
+ ; but gentle on scripts
+ ;
+ [PerlCritic lenient]
+ select = bin/**/*.pl
+ argv = --gentle
+
=item select
One or more L<File::Zglob|File::Zglob> patterns, separated by whitespace or on
diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index bbe8549..74d9fc1 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -138,10 +138,15 @@ sub new_from_conf_file {
sub _load_plugin {
my ( $self, $plugin_name, $plugin_conf ) = @_;
+
+ # Extract first name in case there is a description
+ #
+ my ($plugin_fname) = ( $plugin_name =~ /^(\S+)/ );
+
my $class_name = (
- $plugin_name =~ /^\+/
- ? substr( $plugin_name, 1 )
- : "Code::TidyAll::Plugin::$plugin_name"
+ $plugin_fname =~ /^\+/
+ ? substr( $plugin_fname, 1 )
+ : "Code::TidyAll::Plugin::$plugin_fname"
);
try {
can_load($class_name) || die "not found";
diff --git a/lib/Code/TidyAll/t/Basic.pm b/lib/Code/TidyAll/t/Basic.pm
index 2eb007e..81a60b8 100644
--- a/lib/Code/TidyAll/t/Basic.pm
+++ b/lib/Code/TidyAll/t/Basic.pm
@@ -27,6 +27,9 @@ sub create_dir {
sub tidy {
my ( $self, %params ) = @_;
my $desc = $params{desc};
+ if ( !defined($desc) ) {
+ ($desc) = ( ( caller(1) )[3] =~ /([^:]+$)/ );
+ }
my $root_dir = $self->create_dir( $params{source} );
@@ -104,6 +107,23 @@ sub test_basic : Tests {
);
}
+sub test_multiple_plugin_instances : Tests {
+ my $self = shift;
+ $self->tidy(
+ plugins => {
+ test_plugin('RepeatFoo for txt') => { select => '**/*.txt', times => 2 },
+ test_plugin('RepeatFoo for foo') => { select => '**/foo.*', times => 3 },
+ %UpperText
+ },
+ source => { "foo.txt" => "abc", "foo.dat" => "def", "bar.txt" => "ghi" },
+ dest => {
+ "foo.txt" => scalar( "ABC" x 6 ),
+ "foo.dat" => scalar( "def" x 3 ),
+ "bar.txt" => scalar( "GHI" x 2 )
+ }
+ );
+}
+
sub test_quiet_and_verbose : Tests {
my $self = shift;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git
More information about the Pkg-perl-cvs-commits
mailing list