File: checkpodencoding.pl

package info (click to toggle)
perl 5.24.1-3+deb9u5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,716 kB
  • sloc: perl: 559,611; ansic: 293,886; sh: 67,316; pascal: 7,632; cpp: 3,895; makefile: 2,436; xml: 2,410; yacc: 989; sed: 6; lisp: 1
file content (69 lines) | stat: -rwxr-xr-x 1,447 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env perl
use 5.010;
use open qw< :encoding(utf8) :std >;
use autodie;
use strict;
use File::Find;
use Encode::Guess;

# Check if POD files contain non-ASCII without specifying
# =encoding. Run it as:

## perl Porting/checkpodencoding.pl

find(
    {
        wanted => \&finder,
        no_chdir => 1,
    },
    '.'
);

sub finder {
    my $file = $_;

    return if -d $file or -B $file;

    open my $fh, '<', $file;

    #say STDERR "Checking $file";

    next if
        # Test cases
        $file =~ m[Pod-Simple/t];

    my ($in_pod, $has_encoding, @non_ascii);

    FILE: while (my $line = <$fh>) {
        chomp $line;
        if ($line =~ /^=[a-z]+/) {
            $in_pod = 1;
        }

        if ($in_pod) {
            if ($line =~ /^=encoding (\S+)/) {
                $has_encoding = 1;
                last FILE;
            } elsif ($line =~ /[^[:ascii:]]/) {
                my $encoding = guess_encoding($line);
                push @non_ascii => {
                    num => $.,
                    line => $line,
                    encoding => (ref $encoding ? "$encoding->{Name}?" : 'unknown!'),
                };
            }
        }

        if ($line =~ /^=cut/) {
            $in_pod = 0;
        }
    }

    if (@non_ascii and not $has_encoding) {
        say "$file:";
        $DB::single = 1;
        for (@non_ascii) {
            say "    $_->{num} ($_->{encoding}): $_->{line}";
        }
    }
}