Dist-Zilla-Plugin-Munge-Whitespace
view release on metacpan or search on metacpan
lib/Dist/Zilla/Plugin/Munge/Whitespace.pm view on Meta::CPAN
use 5.006; # our
use strict;
use warnings;
package Dist::Zilla::Plugin::Munge::Whitespace;
our $VERSION = '0.001001';
# ABSTRACT: Strip superfluous spaces from pesky files.
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
use Moose qw( has with around );
use Dist::Zilla::Role::FileMunger 1.000; # munge_file
with 'Dist::Zilla::Role::FileMunger';
has 'preserve_trailing' => ( is => 'ro', isa => 'Bool', lazy => 1, default => sub { undef } );
has 'preserve_cr' => ( is => 'ro', isa => 'Bool', lazy => 1, default => sub { undef } );
has 'filename' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, default => sub { [] } );
has 'match' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, default => sub { [] } );
has '_match_expr' => ( is => 'ro', isa => 'RegexpRef', lazy_build => 1 );
has '_eol_kill_expr' => ( is => 'ro', isa => 'RegexpRef', lazy_build => 1 );
around dump_config => sub {
my ( $orig, $self, @args ) = @_;
my $config = $self->$orig(@args);
my $localconf = $config->{ +__PACKAGE__ } = {};
for my $attr (qw( preserve_trailing preserve_cr filename match )) {
next unless $self->meta->find_attribute_by_name($attr)->has_value($self);
$localconf->{$attr} = $self->can($attr)->($self);
}
$localconf->{ q[$] . __PACKAGE__ . '::VERSION' } = $VERSION
unless __PACKAGE__ eq ref $self;
return $config;
};
__PACKAGE__->meta->make_immutable;
no Moose;
sub mvp_multivalue_args { return qw{ filename match } }
sub munge_file {
my ( $self, $file ) = @_;
return unless $file->name =~ $self->_match_expr;
if ( $file->isa('Dist::Zilla::File::FromCode') ) {
return $self->_munge_from_code($file);
}
return $self->_munge_static($file);
}
sub _build__match_expr {
my ($self) = @_;
my (@matches) = @{ $self->match };
if ( scalar @{ $self->filename } ) {
unshift @matches, sprintf q[\A(?:%s)\z], join q[|], map { quotemeta } @{ $self->filename };
}
my $combined = join q[|], @matches;
## no critic (RegularExpressions::RequireDotMatchAnything)
## no critic (RegularExpressions::RequireLineBoundaryMatching)
## no critic (RegularExpressions::RequireExtendedFormatting)
return qr/$combined/;
}
sub _build__eol_kill_expr {
my ($self) = @_;
## no critic (RegularExpressions::RequireDotMatchAnything)
## no critic (RegularExpressions::RequireLineBoundaryMatching)
( run in 2.997 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )