| 1 | package Dist::Zilla::Plugin::Encoding 6.040; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: set the encoding of arbitrary files | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | with 'Dist::Zilla::Role::EncodingProvider'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Dist::Zilla::Pragmas; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | #pod =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 12 | #pod | ||||||||||||||||||||||||||||
| 13 | #pod This plugin allows you to explicitly set the encoding on some files in your | ||||||||||||||||||||||||||||
| 14 | #pod distribution. You can either specify the exact set of files (with the | ||||||||||||||||||||||||||||
| 15 | #pod "filenames" parameter) or provide the regular expressions to check (using | ||||||||||||||||||||||||||||
| 16 | #pod "match"). | ||||||||||||||||||||||||||||
| 17 | #pod | ||||||||||||||||||||||||||||
| 18 | #pod In your F<dist.ini>: | ||||||||||||||||||||||||||||
| 19 | #pod | ||||||||||||||||||||||||||||
| 20 | #pod [Encoding] | ||||||||||||||||||||||||||||
| 21 | #pod encoding = Latin-3 | ||||||||||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||||||||||
| 23 | #pod filename = t/esperanto.t ; this file is Esperanto | ||||||||||||||||||||||||||||
| 24 | #pod match = ^t/urkish/ ; these are all Turkish | ||||||||||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||||||||||
| 26 | #pod =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 21 | ▶ | sub mvp_multivalue_args { qw(filenames matches ignore) } | ||||||||||||||||||||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 21 | ▶ | sub mvp_aliases { return { filename => 'filenames', match => 'matches' } } | ||||||||||||||||||||||||||
|
Subroutine
mvp_aliases: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | #pod =attr encoding | ||||||||||||||||||||||||||||
| 32 | #pod | ||||||||||||||||||||||||||||
| 33 | #pod This is the encoding to set on the selected files. The special value "bytes" | ||||||||||||||||||||||||||||
| 34 | #pod can be used to indicate raw files that should not be encoded. | ||||||||||||||||||||||||||||
| 35 | #pod | ||||||||||||||||||||||||||||
| 36 | #pod =cut | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 5 | has encoding => ( | |||||||||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||||||||||
| 40 | isa => 'Str', | ||||||||||||||||||||||||||||
| 41 | required => 1, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | #pod =attr filenames | ||||||||||||||||||||||||||||
| 45 | #pod | ||||||||||||||||||||||||||||
| 46 | #pod This is an arrayref of filenames to have their encoding set. | ||||||||||||||||||||||||||||
| 47 | #pod | ||||||||||||||||||||||||||||
| 48 | #pod =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | has filenames => ( | ||||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||
| 52 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 53 | 2 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 5 | ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | #pod =attr matches | ||||||||||||||||||||||||||||
| 57 | #pod | ||||||||||||||||||||||||||||
| 58 | #pod This is an arrayref of regular expressions. Any file whose name matches one of | ||||||||||||||||||||||||||||
| 59 | #pod these regex will have its encoding set. | ||||||||||||||||||||||||||||
| 60 | #pod | ||||||||||||||||||||||||||||
| 61 | #pod =cut | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | has matches => ( | ||||||||||||||||||||||||||||
| 64 | is => 'ro', | ||||||||||||||||||||||||||||
| 65 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 66 | 19 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 5 | ); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | #pod =attr ignore | ||||||||||||||||||||||||||||
| 70 | #pod | ||||||||||||||||||||||||||||
| 71 | #pod This is an arrayref of regular expressions. Any file whose name matches one of | ||||||||||||||||||||||||||||
| 72 | #pod these regex will B<not> have its encoding set. Useful to ignore a few files | ||||||||||||||||||||||||||||
| 73 | #pod that would otherwise be selected by C<matches>. | ||||||||||||||||||||||||||||
| 74 | #pod | ||||||||||||||||||||||||||||
| 75 | #pod =cut | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | has ignore => ( | ||||||||||||||||||||||||||||
| 78 | is => 'ro', | ||||||||||||||||||||||||||||
| 79 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 80 | 20 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 81 | 5 | ); | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 21 | ▶ | sub set_file_encodings { | ||||||||||||||||||||||||||
|
Subroutine
set_file_encodings: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 21 | my ($self) = @_; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # never match (at least the filename characters) | ||||||||||||||||||||||||||||
| 87 | 21 | my $matches_regex = qr/\000/; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 21 | $matches_regex = qr/$matches_regex|$_/ for @{$self->matches}; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # \A\Q$_\E should also handle the `eq` check | ||||||||||||||||||||||||||||
| 92 | 21 | $matches_regex = qr/$matches_regex|\A\Q$_\E/ for @{$self->filenames}; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 21 | ▶ | my( $ignore_regex ) = map { $_ && qr/$_/ } join '|', @{ $self->ignore }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$_ && qr/$_/u
MC/DC100%1/1
$_ && qr/$_/u
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 21 | for my $file (@{$self->zilla->files}) { | |||||||||||||||||||||||||||
| 97 | 101 | ▶ | next unless $file->name =~ $matches_regex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 23 | ▶ | next if $ignore_regex and $file->name =~ $ignore_regex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ignore_regex and $file->name =~ /$ignore_regex/u
MC/DC100%2/2
$ignore_regex and $file->name =~ /$ignore_regex/u
$ignore_regex
$file->name =~ /$ignore_regex/u
Truth table100%3/3
A and B
A= $ignore_regexB= $file->name =~ /$ignore_regex/u
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 22 | $self->log_debug([ | |||||||||||||||||||||||||||
| 102 | 'setting encoding of %s to %s', | ||||||||||||||||||||||||||||
| 103 | $file->name, | ||||||||||||||||||||||||||||
| 104 | $self->encoding, | ||||||||||||||||||||||||||||
| 105 | ]); | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 22 | $file->encoding($self->encoding); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 21 | return; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 114 | 5 | 1; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||