Octets-To-Unicode
view release on metacpan or search on metacpan
script/ru-perltidy view on Meta::CPAN
use open qw/:std :utf8/;
use Getopt::Long qw(:config no_ignore_case);
use Perl::Tidy;
use Pod::Usage;
use Term::ANSIColor qw/:constants/;
use List::Util qw/max/;
use Octets::To::Unicode;
my $parse_options_ok = GetOptions(
'help|h' => \( my $help = 0 ),
'man' => \( my $man = 0 ),
'e|ext=s' => \( my $ext = 'pm,pl,plx,t' ),
'i|interpreters=s' => \( my $interpreters = 'perl,perl5' ),
'n|encodings=s' =>
\( my $encodings = $ENV{'RU-ENCODINGS'} // 'utf-8,cp1251,koi8-r' ),
'b|in-branch' => \( my $in_branch ),
'd|in-dir=s' => \( my $in_dir ),
);
if ( !$parse_options_ok ) {
pod2usage(2);
}
elsif ($help) {
pod2usage(
-sections => "NAME|SYNOPSIS|DESCRIPTION|OPTIONS|SUBCOMMANDS",
-verbose => 99
);
}
elsif ($man) {
pod2usage( -exitval => 0, -verbose => 2 );
}
else {
my @encodings = split /,/, $encodings;
my @files =
@ARGV ? @ARGV
: test_files(
[
$in_branch ? change_files_in_branch()
: $in_dir ? map( file_find($_), split /,/, $in_dir )
: change_files()
],
$ext,
$interpreters
);
my $result = 0;
my $max_length = max map length, @files;
for my $file (@files) {
print "$file ", " " x ( $max_length - length $file );
my ( $unicode, $encoding ) = file_decode $file, \@encodings;
local @ARGV = ();
Perl::Tidy::perltidy(
source => \$unicode,
destination => \my $tidied_code,
);
if ( defined $tidied_code and $unicode eq $tidied_code ) {
print CYAN, "equals";
}
elsif ( defined $tidied_code and length $tidied_code ) {
file_encode $file, $encoding, $tidied_code;
print GREEN, "tidied";
}
else {
print RED, "failed";
$result = 1;
}
print RESET, " in ", YELLOW, $encoding, RESET, "\n";
}
exit $result;
}
__END__
=encoding utf-8
=head1 NAME
B<ru-perltidy> - ÑÑилиÑа Ð´Ð»Ñ ÑоÑмаÑиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ñайлов perltidy Ñ Ð¾Ð¿Ñеделением иÑ
кодиÑовки.
=head1 VERSION
Version 0.06
=head1 SYNOPSIS
ru-perltidy [-h] [--man] [<files> ...] [--ext exts] [--interpreters interpreters] [--in-branch]
=head1 DESCRIPTION
ФоÑмаÑиÑÑÐµÑ ÑÐ°Ð¹Ð»Ñ ÑеÑез perltidy c опÑеделением иÑ
кодиÑовки.
ÐÑÑÑ 4 оÑновнÑе Ñежима ÑабоÑÑ:
# ÐÑÑоÑмаÑиÑоваÑÑ Ð²Ñе изменÑннÑе, но еÑÑ Ð½Ðµ закомиÑеннÑе ÑайлÑ:
$ ru-perltidy
# ÐбÑабоÑаÑÑ Ð¸Ð·Ð¼ÐµÐ½ÑннÑе и закомиÑеннÑе ÑÐ°Ð¹Ð»Ñ Ð² веÑке (branch-е):
$ ru-perltidy --in-branch
# ÐбÑабоÑаÑÑ ÑÐ°Ð¹Ð»Ñ Ð² диÑекÑоÑиÑÑ
:
$ ru-perltidy --in-dir .,/tmp/mydir
# ÐÑÑоÑмаÑиÑоваÑÑ ÑказаннÑе ÑайлÑ:
$ ru-perltidy file1 /root/file2
С помоÑÑÑ Ð¾Ð¿Ñии -e (--ext) можно ÑказаÑÑ ÑаÑÑиÑÐµÐ½Ð¸Ñ Ñайлов Ð´Ð»Ñ ÑоÑмаÑиÑÐ¾Ð²Ð°Ð½Ð¸Ñ (по ÑмолÑÐ°Ð½Ð¸Ñ ÑÑо pm,pl,plx,t):
$ ru-perltidy -e pm,t
( run in 2.152 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )