| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use FindBin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use lib "$FindBin::Bin/../lib"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | # App::SlimPacker is loaded lazily so --help works without PPI installed. | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # minify — PPI-minify Perl source files (comments, POD, whitespace). | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # Thin front-end for App::SlimPacker::Minify::minify_file: reads each file, runs it | ||||||||||||||||||||||||||||
| 12 | # through the PPI minifier and prints the result to STDOUT (or -o FILE). The | ||||||||||||||||||||||||||||
| 13 | # default renames my variables and sub/method names to short names; | ||||||||||||||||||||||||||||
| 14 | # --no-rename-vars / --no-rename-subs keep them and --rewrite enables the | ||||||||||||||||||||||||||||
| 15 | # optional keyword/operator shortening pass. The legacy --rename toggle still | ||||||||||||||||||||||||||||
| 16 | # works as a spelling of --rename-vars. All toggles accept their --no-* form. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 6 | my ($output, $rename_vars, $rename_subs, $rename_exports, $rewrite) = (undef, 1, 1, 0, 0); | |||||||||||||||||||||||||||
| 19 | 6 | Getopt::Long::Configure('no_ignorecase'); | |||||||||||||||||||||||||||
| 20 | 6 | ▶ | Getopt::Long::GetOptionsFromArray(\@ARGV, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 'o|output=s' => \$output, | ||||||||||||||||||||||||||||
| 22 | 'rename!' => \$rename_vars, # legacy alias | ||||||||||||||||||||||||||||
| 23 | 'rename-vars!' => \$rename_vars, | ||||||||||||||||||||||||||||
| 24 | 'rename-subs!' => \$rename_subs, | ||||||||||||||||||||||||||||
| 25 | 'rename-exports!' => \$rename_exports, | ||||||||||||||||||||||||||||
| 26 | 'rewrite!' => \$rewrite, | ||||||||||||||||||||||||||||
| 27 | 'help' => \my $help, | ||||||||||||||||||||||||||||
| 28 | ) or exit 2; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 6 | ▶ | if ($help) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 1 | print <<'USAGE'; | |||||||||||||||||||||||||||
| 32 | minify — PPI-minify Perl source files (comments, POD, whitespace). | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | Usage: minify [OPTIONS] FILE... | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | -o, --output FILE write minified FILE to FILE (needs exactly one input; | ||||||||||||||||||||||||||||
| 37 | default: print to STDOUT) | ||||||||||||||||||||||||||||
| 38 | --rename-vars / --no-rename-vars rename my variables (on by default) | ||||||||||||||||||||||||||||
| 39 | --rename-subs / --no-rename-subs rename sub/method names (on by default) | ||||||||||||||||||||||||||||
| 40 | --rename-exports / --no-rename-exports also rename names in qw() import / | ||||||||||||||||||||||||||||
| 41 | export lists and can()/import() strings (off by | ||||||||||||||||||||||||||||
| 42 | default; only meaningful together with --rename-subs) | ||||||||||||||||||||||||||||
| 43 | --rewrite / --no-rewrite rewrite keywords/operators into shorter equivalent | ||||||||||||||||||||||||||||
| 44 | forms (foreach->for, m/->, drop ; before }, +=1->++, | ||||||||||||||||||||||||||||
| 45 | $x=$x+$y->$x+=$y, print($x)->print $x); experimental, | ||||||||||||||||||||||||||||
| 46 | off by default | ||||||||||||||||||||||||||||
| 47 | -h, --help this help | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | The default renames my variables and sub/method names to short names (a, b, | ||||||||||||||||||||||||||||
| 50 | ...). See App::SlimPacker's process() documentation for what is skipped. | ||||||||||||||||||||||||||||
| 51 | USAGE | ||||||||||||||||||||||||||||
| 52 | 1 | exit 0; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 5 | require App::SlimPacker; | |||||||||||||||||||||||||||
| 56 | 5 | App::SlimPacker->import(qw(minify_file)); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 5 | ▶ | die "minify: missing source file\n" unless @ARGV; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 4 | ▶ | die "minify: -o needs exactly one source file\n" if $output && @ARGV > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$output and @ARGV > 1
MC/DC100%2/2
$output and @ARGV > 1
$output
@ARGV > 1
Truth table100%3/3
A and B
A= $outputB= @ARGV > 1
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | my @out = map { | ||||||||||||||||||||||||||||
| 62 | 3 | my $m = minify_file($_, rename_vars => $rename_vars, | |||||||||||||||||||||||||||
| 63 | rename_subs => $rename_subs, | ||||||||||||||||||||||||||||
| 64 | rename_exports => $rename_exports, | ||||||||||||||||||||||||||||
| 65 | rewrite => $rewrite); | ||||||||||||||||||||||||||||
| 66 | 3 | ▶ | $m .= "\n" unless $m =~ /\n\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 3 | $m; | |||||||||||||||||||||||||||
| 68 | } @ARGV; | ||||||||||||||||||||||||||||
| 69 | 3 | ▶ | if ($output) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | open my $fh, '>', $output or die "Cannot write $output: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 1 | print {$fh} $out[0]; | |||||||||||||||||||||||||||
| 72 | 1 | close $fh; | |||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||
| 74 | 2 | print for @out; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||