[libcode-tidyall-perl] 233/374: support multiple selects/ignores

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:26 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 e3885ddbe7af3ff29c1afe61f42c285e77687fd3
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Fri Sep 14 11:21:18 2012 -0400

    support multiple selects/ignores
---
 lib/Code/TidyAll/Plugin.pm |   42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/lib/Code/TidyAll/Plugin.pm b/lib/Code/TidyAll/Plugin.pm
index 5b83dc4..94f3e92 100644
--- a/lib/Code/TidyAll/Plugin.pm
+++ b/lib/Code/TidyAll/Plugin.pm
@@ -1,6 +1,6 @@
 package Code::TidyAll::Plugin;
 use Code::TidyAll::Util qw(basename read_file write_file);
-use Code::TidyAll::Util::Zglob qw(zglob_to_regex);
+use Code::TidyAll::Util::Zglob qw(zglobs_to_regex);
 use Scalar::Util qw(weaken);
 use Moo;
 
@@ -14,33 +14,43 @@ has 'tidyall' => ( is => 'ro', required => 1, weak_ref => 1 );
 
 # Internal
 has 'ignore_regex' => ( is => 'lazy' );
+has 'ignores'      => ( is => 'lazy' );
 has 'select_regex' => ( is => 'lazy' );
-
-sub BUILD {
-    my ( $self, $params ) = @_;
-
-    my $select = $self->{select};
-    die sprintf( "select is required for '%s'", $self->name ) unless defined($select);
-    die sprintf( "select for '%s' should not begin with /", $self->name )
-      if ( substr( $select, 0, 1 ) eq '/' );
-
-    my $ignore = $self->{ignore};
-    die sprintf( "ignore for '%s' should not begin with /", $self->name )
-      if ( defined($ignore) && substr( $ignore, 0, 1 ) eq '/' );
-}
+has 'selects'      => ( is => 'lazy' );
 
 sub _build_cmd {
     die "no default cmd specified";
 }
 
+sub _build_selects {
+    my ($self) = @_;
+    die sprintf( "select is required for '%s'", $self->name ) unless defined( $self->select );
+    return $self->_parse_zglob_list( $self->select );
+}
+
 sub _build_select_regex {
     my ($self) = @_;
-    return zglob_to_regex( $self->select );
+    return zglobs_to_regex( @{ $self->selects } );
+}
+
+sub _build_ignores {
+    my ($self) = @_;
+    return $self->_parse_zglob_list( $self->ignore );
 }
 
 sub _build_ignore_regex {
     my ($self) = @_;
-    return $self->ignore ? zglob_to_regex( $self->ignore ) : qr/(?!)/;
+    return zglobs_to_regex( @{ $self->ignores } );
+}
+
+sub _parse_zglob_list {
+    my ( $self, $zglob_list ) = @_;
+    $zglob_list = '' if !defined($zglob_list);
+    my @zglobs = split( /\s+/, $zglob_list );
+    if ( my ($bad_zglob) = ( grep { m{^/} } @zglobs ) ) {
+        die "zglob '$bad_zglob' should not begin with slash";
+    }
+    return \@zglobs;
 }
 
 # No-ops by default; may be overridden in subclass

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