| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Test::TrailingSpace; | 
| 2 |  |  |  |  |  |  | $Test::TrailingSpace::VERSION = '0.0501'; | 
| 3 | 2 |  |  | 2 |  | 144268 | use 5.014; | 
|  | 2 |  |  |  |  | 17 |  | 
| 4 | 2 |  |  | 2 |  | 11 | use strict; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 38 |  | 
| 5 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 44 |  | 
| 6 | 2 |  |  | 2 |  | 1030 | use autodie; | 
|  | 2 |  |  |  |  | 32562 |  | 
|  | 2 |  |  |  |  | 9 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 2 |  |  | 2 |  | 14661 | use Test::More; | 
|  | 2 |  |  |  |  | 6155 |  | 
|  | 2 |  |  |  |  | 16 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 2 |  |  | 2 |  | 1807 | use File::Find::Object::Rule 0.0301; | 
|  | 2 |  |  |  |  | 44278 |  | 
|  | 2 |  |  |  |  | 20 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | sub new | 
| 13 |  |  |  |  |  |  | { | 
| 14 | 11 |  |  | 11 | 1 | 36007 | my $class = shift; | 
| 15 |  |  |  |  |  |  |  | 
| 16 | 11 |  |  |  |  | 31 | my $self = bless {}, $class; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 11 |  |  |  |  | 43 | $self->_init(@_); | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 11 |  |  |  |  | 41 | return $self; | 
| 21 |  |  |  |  |  |  | } | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub _filename_regex | 
| 24 |  |  |  |  |  |  | { | 
| 25 | 22 |  |  | 22 |  | 1575 | my $self = shift; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 22 | 100 |  |  |  | 64 | if (@_) | 
| 28 |  |  |  |  |  |  | { | 
| 29 | 11 |  |  |  |  | 18 | $self->{_filename_regex} = shift; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 22 |  |  |  |  | 51 | return $self->{_filename_regex}; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub _root_path | 
| 36 |  |  |  |  |  |  | { | 
| 37 | 22 |  |  | 22 |  | 1225 | my $self = shift; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 22 | 100 |  |  |  | 55 | if (@_) | 
| 40 |  |  |  |  |  |  | { | 
| 41 | 11 |  |  |  |  | 37 | $self->{_root_path} = shift; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 22 |  |  |  |  | 56 | return $self->{_root_path}; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub _abs_path_prune_re | 
| 48 |  |  |  |  |  |  | { | 
| 49 | 22 |  |  | 22 |  | 36 | my $self = shift; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 22 | 100 |  |  |  | 49 | if (@_) | 
| 52 |  |  |  |  |  |  | { | 
| 53 | 11 |  |  |  |  | 39 | $self->{_abs_path_prune_re} = shift; | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 22 |  |  |  |  | 48 | return $self->{_abs_path_prune_re}; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | sub _path_cb | 
| 60 |  |  |  |  |  |  | { | 
| 61 | 22 |  |  | 22 |  | 46 | my $self = shift; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 22 | 100 |  |  |  | 60 | if (@_) | 
| 64 |  |  |  |  |  |  | { | 
| 65 | 11 |  |  |  |  | 23 | $self->{_path_cb} = shift; | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 22 |  |  |  |  | 40 | return $self->{_path_cb}; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | sub _init | 
| 72 |  |  |  |  |  |  | { | 
| 73 | 11 |  |  | 11 |  | 25 | my ( $self, $args ) = @_; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 11 | 50 |  |  |  | 53 | $self->_root_path( exists( $args->{root} ) ? $args->{root} : '.' ); | 
| 76 | 11 |  |  |  |  | 29 | $self->_filename_regex( $args->{filename_regex} ); | 
| 77 | 11 |  |  |  |  | 34 | $self->_abs_path_prune_re( $args->{abs_path_prune_re} ); | 
| 78 | 11 |  |  |  |  | 22 | my $find_cr = $args->{find_cr}; | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 11 | 100 |  |  |  | 28 | my $OPEN_MODE = $find_cr ? '<:raw' : '<'; | 
| 81 | 11 |  |  |  |  | 26 | my $cb = | 
| 82 |  |  |  |  |  |  | "sub { my (\$p) = \@_;open( my \$fh, '$OPEN_MODE', \$p );while ( my \$l = <\$fh> ){chomp(\$l);"; | 
| 83 | 11 |  |  |  |  | 18 | $cb .= | 
| 84 |  |  |  |  |  |  | q#if ( $l =~ /[ \\t]+\\r?\\z/ ){diag("Found trailing space in file '$p'");return 1;}#; | 
| 85 | 11 | 100 |  |  |  | 25 | if ( $args->{find_tabs} ) | 
| 86 |  |  |  |  |  |  | { | 
| 87 | 3 |  |  |  |  | 8 | $cb .= | 
| 88 |  |  |  |  |  |  | q#if ( $l =~ /\\t/ ) { diag("Found hard tabs in file '$p'"); return 1; }#; | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 11 | 100 |  |  |  | 21 | if ($find_cr) | 
| 92 |  |  |  |  |  |  | { | 
| 93 | 2 |  |  |  |  | 5 | $cb .= | 
| 94 |  |  |  |  |  |  | q# if ( $l =~ /\\r\\z/ ) { diag("Found Carriage Returns line endings in file '$p'"); return 1; }#; | 
| 95 |  |  |  |  |  |  | } | 
| 96 | 11 |  |  |  |  | 19 | $cb .= "} return 0;}"; | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | ## no critic | 
| 99 | 11 |  |  |  |  | 2280 | $self->_path_cb( eval($cb) ); | 
| 100 |  |  |  |  |  |  | ## use critic | 
| 101 | 11 |  |  |  |  | 40 | return; | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | sub no_trailing_space | 
| 105 |  |  |  |  |  |  | { | 
| 106 | 11 |  |  | 11 | 1 | 14711 | local $Test::Builder::Level = $Test::Builder::Level + 1; | 
| 107 |  |  |  |  |  |  |  | 
| 108 | 11 |  |  |  |  | 24 | my ( $self, $blurb ) = @_; | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 11 |  |  |  |  | 18 | my $num_found = 0; | 
| 111 |  |  |  |  |  |  |  | 
| 112 | 11 |  |  |  |  | 71 | my $subrule = File::Find::Object::Rule->new; | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 11 |  |  |  |  | 122 | my $abs_path_prune_re = $self->_abs_path_prune_re(); | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | my $rule = $subrule->or( | 
| 117 |  |  |  |  |  |  | $subrule->new->exec( | 
| 118 |  |  |  |  |  |  | sub { | 
| 119 | 121 |  |  | 121 |  | 51203 | my ( $shortname, undef, $path ) = @_; | 
| 120 |  |  |  |  |  |  | return ( | 
| 121 |  |  |  |  |  |  | ( | 
| 122 | 121 |  | 66 |  |  | 2868 | $shortname =~ | 
| 123 |  |  |  |  |  |  | /\A(?:blib|_build|CVS|\.svn|\.bzr|\.hg|\.git)\z/ | 
| 124 |  |  |  |  |  |  | ) | 
| 125 |  |  |  |  |  |  | or ( defined($abs_path_prune_re) | 
| 126 |  |  |  |  |  |  | && ( $path =~ m/$abs_path_prune_re/ ) ) | 
| 127 |  |  |  |  |  |  | ); | 
| 128 |  |  |  |  |  |  | } | 
| 129 | 11 |  |  |  |  | 34 | )->prune->discard, | 
| 130 |  |  |  |  |  |  | $subrule->new->file() | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | # ->exec(sub { print STDERR join(",", "Foo==", @_), "\n"; return 1; }) | 
| 133 |  |  |  |  |  |  | ->name( $self->_filename_regex() ), | 
| 134 |  |  |  |  |  |  | )->start( $self->_root_path() ); | 
| 135 | 11 |  |  |  |  | 6342 | my $cb = $self->_path_cb(); | 
| 136 |  |  |  |  |  |  |  | 
| 137 | 11 |  |  |  |  | 33 | while ( my $path = $rule->match() ) | 
| 138 |  |  |  |  |  |  | { | 
| 139 | 40 |  |  |  |  | 2361 | $num_found += $cb->($path); | 
| 140 |  |  |  |  |  |  | } | 
| 141 |  |  |  |  |  |  |  | 
| 142 | 11 |  |  |  |  | 4622 | return is( $num_found, 0, $blurb ); | 
| 143 |  |  |  |  |  |  | } | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | 1; | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | __END__ |