[libcode-tidyall-perl] 77/374: only call _find_matched_files for process_all. otherwise, use Code::TidyAll::Util::Zglob::zglob_to_regex to find the plugins for each specified file

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:25:52 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 623fd629a09956eef81edd63d2224fe0cf240888
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Thu Jul 5 17:40:09 2012 -0700

    only call _find_matched_files for process_all. otherwise, use Code::TidyAll::Util::Zglob::zglob_to_regex to find the plugins for each specified file
---
 lib/Code/TidyAll.pm        |   17 ++++++++++++++---
 lib/Code/TidyAll/Plugin.pm |    8 ++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index bd9e5cf..4702cef 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -116,7 +116,6 @@ sub new {
     $self->{base_sig} = $self->_sig( [ $Code::TidyAll::VERSION || 0 ] );
     $self->{plugin_objects} =
       [ map { $self->_load_plugin( $_, $self->plugins->{$_} ) } sort keys( %{ $self->plugins } ) ];
-    $self->{matched_files} = $self->_find_matched_files;
 
     return $self;
 }
@@ -143,6 +142,7 @@ sub _load_plugin {
 sub process_all {
     my $self = shift;
 
+    $self->{matched_files} ||= $self->_find_matched_files;
     return $self->process_files( sort keys( %{ $self->matched_files } ) );
 }
 
@@ -161,10 +161,15 @@ sub process_files {
 sub process_file {
     my ( $self, $file ) = @_;
 
-    my @plugins = @{ $self->matched_files->{$file} || [] };
     my $small_path = $self->_small_path($file);
+    my @plugins =
+      $self->matched_files
+      ? @{ $self->matched_files->{$file} }
+      : $self->_plugins_for_path($small_path);
     if ( !@plugins ) {
-        $self->msg( "[no plugins apply] %s", $small_path ) unless $self->quiet;
+        $self->msg( "[no plugins apply%s] %s",
+            $self->mode ? " for mode '" . $self->mode . "'" : "", $small_path )
+          unless $self->quiet;
         return Code::TidyAll::Result->new( file => $file, state => 'no_match' );
     }
 
@@ -327,6 +332,12 @@ sub _find_matched_files {
     return \%matched_files;
 }
 
+sub _plugins_for_path {
+    my ( $self, $path ) = @_;
+
+    return grep { $_->matches_path($path) } @{ $self->plugin_objects };
+}
+
 sub _zglob {
     my ( $self, $expr ) = @_;
 
diff --git a/lib/Code/TidyAll/Plugin.pm b/lib/Code/TidyAll/Plugin.pm
index 2b4de38..d1f6157 100644
--- a/lib/Code/TidyAll/Plugin.pm
+++ b/lib/Code/TidyAll/Plugin.pm
@@ -1,6 +1,7 @@
 package Code::TidyAll::Plugin;
 use Object::Tiny qw(conf ignore name options root_dir select);
 use Code::TidyAll::Util qw(basename read_file tempdir_simple write_file);
+use Code::TidyAll::Util::Zglob qw(zglob_to_regex);
 use strict;
 use warnings;
 
@@ -56,6 +57,13 @@ sub _build_options {
     return \%options;
 }
 
+sub matches_path {
+    my ( $self, $path ) = @_;
+    $self->{select_regex} ||= zglob_to_regex( $self->select );
+    $self->{ignore_regex} ||= ( $self->ignore ? zglob_to_regex( $self->ignore ) : qr/(?!)/ );
+    return $path =~ $self->{select_regex} && $path !~ $self->{ignore_regex};
+}
+
 1;
 __END__
 

-- 
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