Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Encode with strictly valid UTF-8 output once before emitting #37

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/App/ModuleBuildTiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Carp qw/croak/;
use Config;
use CPAN::Meta;
use Data::Section::Simple 'get_data_section';
use Encode qw/encode_utf8 decode_utf8/;
use Encode qw/encode decode/;
use ExtUtils::Manifest qw/manifind maniskip maniread/;
use File::Basename qw/dirname/;
use File::Path qw/mkpath/;
Expand Down Expand Up @@ -41,7 +41,7 @@ sub prompt {

my $ans = <STDIN> // '';
chomp $ans;
return $ans ne '' ? decode_utf8($ans) : $def // '';
return $ans ne '' ? decode('UTF-8', $ans) : $def // '';
}

sub create_license_for {
Expand Down Expand Up @@ -200,7 +200,12 @@ my %actions = (

my $dist = App::ModuleBuildTiny::Dist->new(regenerate => \%files);
for my $filename ($dist->files) {
write_text($filename, $dist->get_file($filename)) if $dist->is_generated($filename);
if ($dist->is_generated($filename)) {
open my $fh, '> :raw', $filename or die "Could not generate $filename: $!";
my $out = $dist->get_file($filename);
$out = Encode::encode('UTF-8', $out) if $filename =~ /META.yml/;
print $fh $out;
}
}
return 0;
},
Expand Down Expand Up @@ -241,7 +246,7 @@ my %actions = (
my $config = read_json($config_file);
croak "Config not readable, please run mbtiny configure" if not defined $config;

my $distname = decode_utf8(shift @arguments || croak 'No distribution name given');
my $distname = decode('UTF-8', shift @arguments || croak 'No distribution name given');
croak "Directory $distname already exists" if -e $distname;

my %args = (
Expand Down
3 changes: 1 addition & 2 deletions lib/App/ModuleBuildTiny/Dist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ our $VERSION = '0.023';
use CPAN::Meta;
use Carp qw/croak/;
use Config;
use Encode qw/encode_utf8 decode_utf8/;
use File::Basename qw/basename dirname/;
use File::Copy qw/copy/;
use File::Path qw/mkpath rmtree/;
Expand Down Expand Up @@ -253,7 +252,7 @@ sub get_file {
my ($self, $filename) = @_;
return if not exists $self->{files}{$filename};
my $raw = $self->{files}{$filename};
return $raw ? encode_utf8($raw) : read_binary($filename);
return $raw ? $raw : read_binary($filename);
}

sub is_generated {
Expand Down