lib/Dist/Zilla/Plugin/Git/RequireUnixEOL.pm

filter: Statementstmt 100% 62 / 62 Branchbran 77.7% 14 / 18 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 2 totaltotal 94.0% 94 / 100 CC 12 SCAR 17.4
CC
12
Cov
95%
before_build
11.0
_git_ls_files
2.0
BEGIN
1.0
CRAP 5.7
↑ Summary
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
BranchTrueFalseTotal
unless @files 1 3 4
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
BranchTrueFalseTotal
open my $fh, "<", $file or croak("Could not open ${file}: $!") 3 0 3
44  
45 # On Windows default is :crlf, which hides \r\n
46 3 ▶ binmode $fh, ':raw' or croak "binmode failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh, ":raw" or croak("binmode failed: $!") 3 0 3
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
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 12 3 15
52 12 $line_no++;
53  
54 12 ▶ if ( ( $windows_line_ending_found == 0 ) and ( $line =~ m{\r$}xsm ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($windows_line_ending_found == 0 and $line =~ /\r$/msx) 1 11 12
Condition100%3/3
$windows_line_ending_found == 0 and $line =~ /\r$/msx
!ll&&!rl&&r
291
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($line =~ /[ \t]+\r?\n$/msx) 1 11 12
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
BranchTrueFalseTotal
close $fh or croak("Could not read ${file}: $!") 3 0 3
65 }
66  
67 3 ▶ if (@errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@errors) 2 1 3
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
BranchTrueFalseTotal
if $files_f->is_failed 0 4 4
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__
↑ Summary