use App::Codeowners::Options;
use App::Codeowners::Util qw(find_codeowners_in_directory run_git git_ls_files git_toplevel);
use Color::ANSI::Util 0.03 qw(ansifg);
-use Encode qw(encode);
use File::Codeowners;
use Path::Tiny;
my $command = $opts->command;
my $handler = $self->can("_command_$command")
or die "Unknown command: $command\n";
+
+ binmode(STDOUT, ':encoding(UTF-8)');
$self->$handler($opts);
exit 0;
use parent 'App::Codeowners::Formatter';
use App::Codeowners::Util qw(stringify);
-use Encode qw(encode);
sub start {
my $self = shift;
my $self = shift;
my $result = shift;
- $self->text_csv->print($self->handle, [map { encode('UTF-8', stringify($_)) } @$result]);
+ $self->text_csv->print($self->handle, [map { stringify($_) } @$result]);
}
=attr text_csv
my %options;
$options{pretty} = 1 if lc($self->format) eq 'pretty';
- my $json = JSON::MaybeXS->new(canonical => 1, utf8 => 1, %options);
+ my $json = JSON::MaybeXS->new(canonical => 1, %options);
my $columns = $self->columns;
$results = [map { +{zip @$columns, @$_} } @$results];
use App::Codeowners::Util qw(stringf zip);
use Color::ANSI::Util 0.03 qw(ansifg);
-use Encode qw(encode);
sub stream {
my $self = shift;
);
my $text = stringf($self->format, %info);
- print { $self->handle } encode('UTF-8', $text), "\n";
+ print { $self->handle } $text, "\n";
}
sub _expand_filter_args {
use parent 'App::Codeowners::Formatter';
use App::Codeowners::Util qw(stringify);
-use Encode qw(encode);
sub finish {
my $self = shift;
rows => [$self->columns, map { [map { stringify($_) } @$_] } @$results],
backend => $ENV{PERL_TEXT_TABLE},
);
- print { $self->handle } encode('UTF-8', $table);
+ print { $self->handle } $table;
}
1;
use warnings;
use strict;
+use Encode qw(decode);
use Getopt::Long 2.39 ();
use Path::Tiny;
my $class = shift;
my @args = @_;
+ # assume UTF-8 args if non-ASCII
+ @args = map { decode('UTF-8', $_) } @args if grep { /\P{ASCII}/ } @args;
+
my $self = bless {}, $class;
my @args_copy = @args;
my $self = shift;
my $path = shift or _usage(q{$codeowners->write_to_filepath($filepath)});
- path($path)->spew_utf8([map { "$_\n" } @{$self->write_to_array('')}]);
+ path($path)->spew_utf8([map { "$_\n" } @{$self->write_to_array}]);
}
=method write_to_fh
=cut
sub write_to_fh {
- my $self = shift;
- my $fh = shift or _usage(q{$codeowners->write_to_fh($fh)});
+ my $self = shift;
+ my $fh = shift or _usage(q{$codeowners->write_to_fh($fh)});
+ my $charset = shift;
- for my $line (@{$self->write_to_array}) {
+ for my $line (@{$self->write_to_array($charset)}) {
print $fh "$line\n";
}
}
=cut
sub write_to_string {
- my $self = shift;
+ my $self = shift;
+ my $charset = shift;
- my $str = join("\n", @{$self->write_to_array}) . "\n";
+ my $str = join("\n", @{$self->write_to_array($charset)}) . "\n";
return \$str;
}
sub write_to_array {
my $self = shift;
- my $charset = shift // 'UTF-8';
+ my $charset = shift;
my @format;
}
}
- if ($charset) {
+ if (defined $charset) {
$_ = encode($charset, $_) for @format;
}
return \@format;