| 1 | package Dist::Zilla::Plugin::Git::RequireUnixEOL; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '1.001'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | with 'Dist::Zilla::Role::BeforeBuild'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Git::Background 0.003; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | sub mvp_multivalue_args { return (qw( ignore )) } | ||||||||||||||||||||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | has _git => ( | ||||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||
| 22 | isa => 'Git::Background', | ||||||||||||||||||||||||||||
| 23 | lazy => 1, | ||||||||||||||||||||||||||||
| 24 | 4 | ▶ | default => sub { Git::Background->new( path( shift->zilla->root )->absolute ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 2 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | has ignore => ( | ||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||
| 29 | isa => 'Maybe[ArrayRef]', | ||||||||||||||||||||||||||||
| 30 | 3 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 2 | ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 4 | ▶ | sub before_build { | ||||||||||||||||||||||||||
|
Subroutine
before_build: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 4 | my %ignored_file = map { $_ => 1 } @{ $self->ignore }; | |||||||||||||||||||||||||||
| 37 | 4 | my @files = grep { !exists $ignored_file{$_} } $self->_git_ls_files(); | |||||||||||||||||||||||||||
| 38 | 4 | ▶ | return if !@files; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | my @errors; | |||||||||||||||||||||||||||
| 41 | FILE: | ||||||||||||||||||||||||||||
| 42 | 3 | for my $file (@files) { | |||||||||||||||||||||||||||
| 43 | 3 | ▶ | open my $fh, '<', $file or croak "Could not open $file: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # On Windows default is :crlf, which hides \r\n | ||||||||||||||||||||||||||||
| 46 | 3 | ▶ | binmode $fh, ':raw' or croak "binmode failed: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 3 | my $windows_line_ending_found = 0; | |||||||||||||||||||||||||||
| 49 | 3 | my $line_no = 0; | |||||||||||||||||||||||||||
| 50 | LINE: | ||||||||||||||||||||||||||||
| 51 | 3 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 12 | $line_no++; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 12 | ▶ | if ( ( $windows_line_ending_found == 0 ) and ( $line =~ m{\r$}xsm ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$windows_line_ending_found == 0 and $line =~ /\r$/msx
MC/DC100%2/2
$windows_line_ending_found == 0 and $line =~ /\r$/msx
$windows_line_ending_found == 0
$line =~ /\r$/msx
Truth table100%3/3
A and B
A= $windows_line_ending_found == 0B= $line =~ /\r$/msx
| |||||||||||||||||||||||||||||
| 55 | 1 | $windows_line_ending_found = 1; | |||||||||||||||||||||||||||
| 56 | 1 | push @errors, "File $file uses Windows EOL (found on line $line_no)"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 12 | ▶ | if ( $line =~ m{[ \t]+\r?\n$}xsm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 1 | push @errors, "File $file has trailing whitespace on line $line_no"; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | close $fh or croak "Could not read $file: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 3 | ▶ | if (@errors) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 2 | $self->log_fatal( join "\n", q{-} x 60, @errors ); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | ▶ | sub _git_ls_files { | ||||||||||||||||||||||||||
|
Subroutine
_git_ls_files: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 75 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 4 | my $git = $self->_git; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 4 | my $files_f = $git->run('ls-files')->await; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | ▶ | $self->log_fatal( scalar $files_f->failure ) if $files_f->is_failed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 4 | my @files = $files_f->stdout; | |||||||||||||||||||||||||||
| 84 | 4 | return @files; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 2 | 1; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||