This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
embed.fnc: Mark unlnk as Core only
[perl5.git] / Porting / checkpodencoding.pl
CommitLineData
49781f4a
AB
1#!/usr/bin/env perl
2use 5.010;
3use open qw< :encoding(utf8) :std >;
4use autodie;
5use strict;
6use File::Find;
7use Encode::Guess;
8
9# Check if POD files contain non-ASCII without specifying
10# =encoding. Run it as:
11
12## perl Porting/checkpodencoding.pl
13
14find(
15 {
16 wanted => \&finder,
17 no_chdir => 1,
18 },
19 '.'
20);
21
22sub finder {
23 my $file = $_;
24
ea821e91 25 return if -d $file or -B $file;
49781f4a
AB
26
27 open my $fh, '<', $file;
28
29 #say STDERR "Checking $file";
30
31 next if
32 # Test cases
df711a60 33 $file =~ m[Pod-Simple/t];
49781f4a
AB
34
35 my ($in_pod, $has_encoding, @non_ascii);
36
37 FILE: while (my $line = <$fh>) {
38 chomp $line;
df711a60 39 if ($line =~ /^=[a-z]+/) {
49781f4a
AB
40 $in_pod = 1;
41 }
42
43 if ($in_pod) {
df711a60 44 if ($line =~ /^=encoding (\S+)/) {
49781f4a
AB
45 $has_encoding = 1;
46 last FILE;
df711a60 47 } elsif ($line =~ /[^[:ascii:]]/) {
49781f4a
AB
48 my $encoding = guess_encoding($line);
49 push @non_ascii => {
50 num => $.,
51 line => $line,
52 encoding => (ref $encoding ? "$encoding->{Name}?" : 'unknown!'),
53 };
54 }
55 }
56
df711a60 57 if ($line =~ /^=cut/) {
49781f4a
AB
58 $in_pod = 0;
59 }
60 }
61
62 if (@non_ascii and not $has_encoding) {
63 say "$file:";
64 $DB::single = 1;
65 for (@non_ascii) {
66 say " $_->{num} ($_->{encoding}): $_->{line}";
67 }
68 }
69}