| 1 | 2 | ▶ | use 5.10.1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Test::EOF; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.0804'; | |||||||||||||||||||||||||||
| 8 | # ABSTRACT: Check correct end of files in a project. | ||||||||||||||||||||||||||||
| 9 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Cwd qw/cwd/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use File::Find; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use File::ReadBackwards; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Test::Builder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | my $perlstart = qr/^#!.*perl/; | |||||||||||||||||||||||||||
| 17 | 2 | my $test = Test::Builder->new; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | 1 | my $caller = caller; | |||||||||||||||||||||||||||
| 22 | { | ||||||||||||||||||||||||||||
| 23 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | *{ $caller.'::all_perl_files_ok'} = \&all_perl_files_ok; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 1 | $test->exported_to($caller); | |||||||||||||||||||||||||||
| 27 | 1 | $test->plan(@_); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | sub all_perl_files_ok { | ||||||||||||||||||||||||||
|
Subroutine
all_perl_files_ok: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | my $options = ref $_[0] eq 'HASH' ? shift : ref $_[-1] eq 'HASH' ? pop : {}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 32 | 2 | my @files = _all_perl_files(@_); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | $test->expected_tests; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # no need to check then... | ||||||||||||||||||||||||||||
| 37 | 2 | ▶ | if(exists $options->{'minimum_newlines'} && $options->{'minimum_newlines'} <= 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $options->{"minimum_newlines"} and $options->{"minimum_newlines"} <= 0
MC/DC0%0/2
exists $options->{"minimum_newlines"} and $options->{"minimum_newlines"} <= 0
exists $options->{"minimum_newlines"}
$options->{"minimum_newlines"} <= 0
Truth table66%2/3
A and B
A= exists $options->{"minimum_newlines"}B= $options->{"minimum_newlines"} <= 0
| |||||||||||||||||||||||||||||
| 38 | 0 | return 1; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | foreach my $file (@files) { | |||||||||||||||||||||||||||
| 42 | 2 | _check_perl_file($file, $options); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | ▶ | sub _check_perl_file { | ||||||||||||||||||||||||||
|
Subroutine
_check_perl_file: called CC=12 SCAR=31.8
| |||||||||||||||||||||||||||||
| 47 | 2 | my $file = shift; | |||||||||||||||||||||||||||
| 48 | 2 | my $options = shift; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | $options->{'minimum_newlines'} ||= 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$options->{"minimum_newlines"} ||= 1
MC/DC100%1/1
$options->{"minimum_newlines"} ||= 1
$options->{"minimum_newlines"}
Truth table100%2/2
A
A= $options->{"minimum_newlines"}
| |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | if(!exists $options->{'maximum_newlines'}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 52 | 2 | $options->{'maximum_newlines'} = $options->{'minimum_newlines'} + 3; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | ▶ | elsif(exists $options->{'maximum_newlines'} && $options->{'maximum_newlines'} < $options->{'minimum_newlines'}) { | |||||||||||||||||||||||||||
|
Condition0%0/3
exists $options->{"maximum_newlines"} and $options->{"maximum_newlines"} < $options->{"minimum_newlines"}
MC/DC0%0/2
exists $options->{"maximum_newlines"} and $options->{"maximum_newlines"} < $options->{"minimum_newlines"}
exists $options->{"maximum_newlines"}
$options->{"maximum_newlines"} < $options->{"minimum_newlines"}
Truth table0%0/3
A and B
A= exists $options->{"maximum_newlines"}B= $options->{"maximum_newlines"} < $options->{"minimum_newlines"}
| |||||||||||||||||||||||||||||
| 55 | 0 | $options->{'maximum_newlines'} = $options->{'minimum_newlines'}; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | ▶ | if($options->{'strict'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | $options->{'minimum_newlines'} = 1; | |||||||||||||||||||||||||||
| 60 | 0 | $options->{'maximum_newlines'} = 1; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | $file = _module_to_path($file); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | my $reader = File::ReadBackwards->new($file) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | my $linecount = 0; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | LINE: | ||||||||||||||||||||||||||||
| 70 | 2 | ▶ | while(my $line = $reader->readline) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 4 | ▶ | ++$linecount if $line =~ m{\v$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 4 | ▶ | next LINE if $line =~ m{^\v$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 2 | last LINE; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | ▶ | if($linecount < $options->{'minimum_newlines'}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 77 | 0 | my $wanted = make_wanted($options); | |||||||||||||||||||||||||||
| 78 | 0 | $test->ok(0, "Not enough line breaks (had $linecount, wanted $wanted) at the end of $file"); | |||||||||||||||||||||||||||
| 79 | 0 | return 0; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | elsif($linecount > $options->{'maximum_newlines'}) { | ||||||||||||||||||||||||||||
| 82 | 0 | my $wanted = make_wanted($options); | |||||||||||||||||||||||||||
| 83 | 0 | $test->ok(0, "Too many line breaks (had $linecount, wanted $wanted) at the end of $file "); | |||||||||||||||||||||||||||
| 84 | 0 | return 0; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 2 | $test->ok(1, "Just the right number of line breaks at the end of $file"); | |||||||||||||||||||||||||||
| 87 | 2 | return 1; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub make_wanted { | ||||||||||||||||||||||||||
|
Subroutine
make_wanted: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 0 | my $options = shift; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | return $options->{'minimum_newlines'} if $options->{'minimum_newlines'} == $options->{'maximum_newlines'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | return sprintf "%d to %d" => $options->{'minimum_newlines'}, $options->{'maximum_newlines'}; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | ▶ | sub _all_perl_files { | ||||||||||||||||||||||||||
|
Subroutine
_all_perl_files: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 98 | 2 | ▶ | my @base_dirs = @_ ? @_ : cwd(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 2 | my @found; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 4 | ▶ | my $wants = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.8
| |||||||||||||||||||||||||||||
| 102 | 4 | ▶ | return if $File::Find::dir =~ m{ [\\/]? (?:CVS|\.svn) [\\/] }x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 4 | ▶ | return if $File::Find::dir =~ m{ [\\/]? blib [\\/] (?: libdoc | man\d) $ }x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 4 | ▶ | return if $File::Find::dir =~ m{ [\\/]? inc }x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 4 | ▶ | return if $File::Find::name =~ m{ Build $ }xi; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 4 | ▶ | return unless -f -r $File::Find::name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 2 | push @found => File::Spec->no_upwards($File::Find::name); | |||||||||||||||||||||||||||
| 108 | 2 | }; | |||||||||||||||||||||||||||
| 109 | 2 | my $find_arg = { | |||||||||||||||||||||||||||
| 110 | wanted => $wants, | ||||||||||||||||||||||||||||
| 111 | no_chdir => 1, | ||||||||||||||||||||||||||||
| 112 | }; | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 2 | find($find_arg, @base_dirs); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 2 | ▶ | my @perls = grep { _is_perl($_) || _is_perl($_) } @found; | ||||||||||||||||||||||||||
|
Condition33%1/3
_is_perl($_) || _is_perl($_)
MC/DC0%0/2
_is_perl($_) || _is_perl($_)
_is_perl($_)
_is_perl($_)
Truth table33%1/3
A || B
A= _is_perl($_)B= _is_perl($_)
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | return @perls; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | ▶ | sub _is_perl { | ||||||||||||||||||||||||||
|
Subroutine
_is_perl: called CC=8 SCAR=31.3
| |||||||||||||||||||||||||||||
| 122 | 2 | my $file = shift; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | # module | ||||||||||||||||||||||||||||
| 125 | 2 | ▶ | return 1 if $file =~ m{\.pm$}i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 1 | ▶ | return 1 if $file =~ m{::}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # script | ||||||||||||||||||||||||||||
| 129 | 1 | ▶ | return 1 if $file =~ m{\.pl}i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 1 | ▶ | return 1 if $file =~ m{\.t$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | open my $fh, '<', $file or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | my $first = <$fh>; | |||||||||||||||||||||||||||
| 134 | 0 | ▶ | if(defined $first && $first =~ $perlstart) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $first and $first =~ /$perlstart/
MC/DC0%0/2
defined $first and $first =~ /$perlstart/
defined $first
$first =~ /$perlstart/
Truth table0%0/3
A and B
A= defined $firstB= $first =~ /$perlstart/
| |||||||||||||||||||||||||||||
| 135 | 0 | close $fh; | |||||||||||||||||||||||||||
| 136 | 0 | return 1; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # nope | ||||||||||||||||||||||||||||
| 140 | 0 | return; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 2 | ▶ | sub _module_to_path { | ||||||||||||||||||||||||||
|
Subroutine
_module_to_path: called CC=4 SCAR=24.2
| |||||||||||||||||||||||||||||
| 144 | 2 | my $file = shift; | |||||||||||||||||||||||||||
| 145 | 2 | ▶ | return $file unless $file =~ m{::}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | my @parts = split /::/ => $file; | |||||||||||||||||||||||||||
| 147 | 0 | my $module = File::Spec->catfile(@parts) . '.pm'; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | CANDIDATE: | ||||||||||||||||||||||||||||
| 150 | 0 | foreach my $dir (@INC) { | |||||||||||||||||||||||||||
| 151 | 0 | my $candidate = File::Spec->catfile($dir, $module); | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | next CANDIDATE if !-e -f -r $candidate; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | return $candidate; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 0 | return $file; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 2 | 1; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | __END__ | ||||||||||||||||||||||||||||