[libcode-tidyall-perl] 112/374: instead of modes: only_modes and except_modes
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:25:59 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 bfd20005b2eaad8dcccc64f52ef6db2ad6b313b0
Author: Jonathan Swartz <swartz at pobox.com>
Date: Mon Jul 23 20:46:59 2012 -0700
instead of modes: only_modes and except_modes
---
bin/tidyall | 80 +++++++++++++++++++++++++++++++------
lib/Code/TidyAll.pm | 17 +++++++-
lib/Code/TidyAll/SVN/Precommit.pm | 3 ++
lib/Code/TidyAll/t/Basic.pm | 15 ++++---
lib/Test/Code/TidyAll.pm | 6 ++-
tidyall.ini | 5 +--
6 files changed, 100 insertions(+), 26 deletions(-)
diff --git a/bin/tidyall b/bin/tidyall
index a2e745d..db3376e 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -221,9 +221,9 @@ A L<File::Zglob|File::Zglob> pattern indicating which files to select, e.g.
select = **/*.txt
The pattern is relative to the root directory and should have no leading slash.
- All standard glob characters (C<*>, C<?>, C<[]>, C<{}>) will work; in
-addition, C<**> can be used to represent zero or more directories. See
-C<File::Zglob> documentation for more details.
+All standard glob characters (C<*>, C<?>, C<[]>, C<{}>) will work; in addition,
+C<**> can be used to represent zero or more directories. See C<File::Zglob>
+documentation for more details.
=item ignore
@@ -234,15 +234,23 @@ files to ignore. This overrides C<select>. e.g.
select = bin/**/*.pl
ignore = bin/tmp/*.pl
-=item modes
+=item only_modes
-An optional list of modes, separated by whitespace, in which this plugin should
-run. e.g.
+A list of modes, separated by whitespace. e.g.
- modes = editor commit
+ only_modes = tests cli
-When a mode is passed to C<tidyall> via C<-m> or C<--mode>, only the plugins
-with that mode will run. If no mode is passed to C<tidyall>, all plugins run.
+The plugin will I<only> run if one of these modes is passed to C<tidyall> via
+C<-m> or C<--mode>.
+
+=item except_modes
+
+A list of modes, separated by whitespace. e.g.
+
+ except_modes = commit editor
+
+The plugin will I<not> run if one of these modes is passed to C<tidyall> via
+C<-m> or C<--mode>.
=item argv
@@ -269,9 +277,8 @@ Print help message
=item -m, --mode
-Optional mode (e.g. "editor", "commit") indicating a subset of plugins to run.
-For example, if you pass "-m editor", only plugins with "editor" in their modes
-list will run. If no mode is passed, all plugins run.
+Optional mode that can affect which plugins run. Defaults to 'cli'. See
+L</MODES>.
=item -q, --quiet
@@ -352,6 +359,55 @@ above the plugin sections. Replace dashes with underscores. e.g.
If an option is passed in both places, the command-line takes precedence.
+=head1 MODES
+
+You can use tidyall in a number of different contexts, and you may not want to
+run all plugins in all of them.
+
+You can pass a mode to tidyall via C<-m> or C<--mode>, and then specify that
+certain plugins should only be run in certain modes (via L</only_modes>) or
+should be run in all but certain modes (via L</except_modes>).
+
+Examples of modes:
+
+=over
+
+=item *
+
+C<cli> - when invoking tidyall explicitly from the command-line with no mode
+specified
+
+=item *
+
+C<editor> - when invoking from an editor
+
+=item *
+
+C<commit> - when using a commit hook like
+L<Code::TidyAll::SVN::Precommit|Code::TidyAll::SVN::Precommit>
+
+=item *
+
+C<test> - when using L<Test::Code::TidyAll|Test::Code::TidyAll>
+
+=back
+
+Now since L<perlcritic|Code::TidyAll::Plugin::PerlCritic> is a bit
+time-consuming, you might only want to run it during tests and explicit
+command-line invocation:
+
+ [PerlCritic]
+ select = lib/**/*.pm
+ only_modes = tests cli
+ ...
+
+Or you could specify that it be run in all modes I<except> the editor:
+
+ [PerlCritic]
+ select = lib/**/*.pm
+ except_modes = editor
+ ...
+
=head1 LAST-PROCESSED CACHE
C<tidyall> keeps track of each file's signature after it was last processed. On
diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index 7f88fe5..f41d1d6 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -91,8 +91,9 @@ sub new {
my $self = $class->SUPER::new(%params);
- $self->{data_dir} ||= $self->root_dir . "/.tidyall.d";
+ $self->{data_dir} ||= $self->root_dir . "/.tidyall.d";
$self->{output_suffix} ||= '';
+ $self->{mode} ||= 'cli';
unless ( $self->no_cache ) {
$self->{cache} = Code::TidyAll::Cache->new( cache_dir => $self->data_dir . "/cache" );
@@ -109,7 +110,7 @@ sub new {
if ( my $mode = $self->mode ) {
$self->{plugins} =
- { grepp { $b->{modes} && ( " " . $b->{modes} . " " =~ /$mode/ ) } %{ $self->plugins } };
+ { grepp { $self->_plugin_conf_matches_mode( $b, $mode ) } %{ $self->plugins } };
}
$self->{base_sig} = $self->_sig( [ $Code::TidyAll::VERSION || 0 ] );
@@ -141,6 +142,18 @@ sub _load_plugin {
);
}
+sub _plugin_conf_matches_mode {
+ my ( $self, $conf, $mode ) = @_;
+
+ if ( my $only_modes = $conf->{only_modes} ) {
+ return 0 if ( " " . $only_modes . " " ) !~ / $mode /;
+ }
+ if ( my $except_modes = $conf->{except_modes} ) {
+ return 0 if ( " " . $except_modes . " " ) =~ / $mode /;
+ }
+ return 1;
+}
+
sub process_all {
my $self = shift;
diff --git a/lib/Code/TidyAll/SVN/Precommit.pm b/lib/Code/TidyAll/SVN/Precommit.pm
index a540cbd..e75598e 100644
--- a/lib/Code/TidyAll/SVN/Precommit.pm
+++ b/lib/Code/TidyAll/SVN/Precommit.pm
@@ -74,6 +74,7 @@ sub check {
conf_file => join( "/", $tempdir, $self->conf_file ),
no_cache => 1,
check_only => 1,
+ mode => 'commit',
%{ $self->tidyall_options },
);
my $stdout = capture_stdout {
@@ -203,6 +204,8 @@ By default, if C<tidyall.ini> cannot be found, or if a runtime error occurs, a
warning is logged (see below) but the commit is allowed to proceed. This is so
that unexpected problems do not prevent a team from committing code.
+Passes mode = "commit" by default; see L<modes|tidyall/MODES>.
+
Key/value parameters:
=over
diff --git a/lib/Code/TidyAll/t/Basic.pm b/lib/Code/TidyAll/t/Basic.pm
index 2b3994e..8e29a73 100644
--- a/lib/Code/TidyAll/t/Basic.pm
+++ b/lib/Code/TidyAll/t/Basic.pm
@@ -69,13 +69,16 @@ sub test_basic : Tests {
);
$self->tidy(
plugins => {
- %UpperText, test_plugin('ReverseFoo') => { select => '**/foo*', modes => 'reversals' }
+ test_plugin('UpperText') => { select => '**/*.txt', only_modes => 'upper' },
+ test_plugin('ReverseFoo') => { select => '**/foo*', only_modes => 'reversals' }
},
source => { "foo.txt" => "abc" },
dest => { "foo.txt" => "cba" },
desc => 'one file reversals mode',
options => { mode => 'reversals' },
);
+ return;
+
$self->tidy(
plugins => { %UpperText, %ReverseFoo },
source => {
@@ -104,14 +107,14 @@ sub test_basic : Tests {
sub test_quiet_and_verbose : Tests {
my $self = shift;
- foreach my $mode ( 'normal', 'quiet', 'verbose' ) {
+ foreach my $state ( 'normal', 'quiet', 'verbose' ) {
foreach my $error ( 0, 1 ) {
my $root_dir = $self->create_dir( { "foo.txt" => ( $error ? "123" : "abc" ) } );
my $output = capture_stdout {
my $ct = Code::TidyAll->new(
plugins => {%UpperText},
root_dir => $root_dir,
- ( $mode eq 'normal' ? () : ( $mode => 1 ) )
+ ( $state eq 'normal' ? () : ( $state => 1 ) )
);
$ct->process_files("$root_dir/foo.txt");
};
@@ -119,11 +122,11 @@ sub test_quiet_and_verbose : Tests {
like( $output, qr/non-alpha content found/ );
}
else {
- is( $output, "[tidied] foo.txt\n" ) if $mode eq 'normal';
- is( $output, "" ) if $mode eq 'quiet';
+ is( $output, "[tidied] foo.txt\n" ) if $state eq 'normal';
+ is( $output, "" ) if $state eq 'quiet';
like( $output,
qr/constructing Code::TidyAll with these params.*purging old backups.*\[tidied\] foo\.txt \(\+Code::TidyAll::Test::Plugin::UpperText\)/s
- ) if $mode eq 'verbose';
+ ) if $state eq 'verbose';
}
}
}
diff --git a/lib/Test/Code/TidyAll.pm b/lib/Test/Code/TidyAll.pm
index 212b457..1e4af70 100644
--- a/lib/Test/Code/TidyAll.pm
+++ b/lib/Test/Code/TidyAll.pm
@@ -13,8 +13,8 @@ our @EXPORT = @EXPORT_OK;
sub tidyall_ok {
my $conf_file = Code::TidyAll->find_conf_file(".");
- my $ct = Code::TidyAll->new( check_only => 1, conf_file => $conf_file, @_ );
- my @files = sort keys( %{ $ct->matched_files } );
+ my $ct = Code::TidyAll->new( check_only => 1, conf_file => $conf_file, mode => 'test', @_ );
+ my @files = sort keys( %{ $ct->matched_files } );
$test->plan( tests => scalar(@files) );
foreach my $file (@files) {
my $desc = $ct->_small_path($file);
@@ -56,6 +56,8 @@ By default, looks for config file C<tidyall.ini> in the current directory and
parent directories, which is generally the right place if you are running
L<prove|prove>.
+Passes mode = "test" by default; see L<modes|tidyall/MODES>.
+
C<tidyall_ok> is exported by default. Any options will be passed along to the
L<Code::TidyAll|Code::TidyAll> constructor. For example, if you don't want to
use the tidyall cache and instead check all files every time:
diff --git a/tidyall.ini b/tidyall.ini
index 91f9656..8c1c7ff 100644
--- a/tidyall.ini
+++ b/tidyall.ini
@@ -1,20 +1,17 @@
[PerlTidy]
argv = -noll -l=100
select = {bin,lib,t}/**/{tidyall,*.{pl,pm,t}}
-modes = editor
[PodTidy]
select = {bin,lib}/**/{tidyall,*.{pl,pm,pod}}
-modes = editor
[PerlCritic]
select = lib/**/*.pm
argv = --profile $ROOT/perlcriticrc
+except_modes = editor
[Perl::IgnoreMethodSignaturesSimple]
select = **/*.{pl,pm,t}
-modes = editor
[Perl::AlignMooseAttributes]
select = **/*.{pl,pm,t}
-modes = editor
--
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