bin/minify

filter: Statementstmt 100% 35 / 35 Branchbran 78.5% 11 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 94.9% 56 / 59 CC 1 SCAR 0.0
CC
1
Cov
94%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/App/SlimPacker.pm ↑ Summary
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
BranchTrueFalseTotal
&Getopt::Long::GetOptionsFromArray(\@ARGV, "o|output=s", \$output, "rename!", \$rename_vars, "rename-vars!", \$rename_vars, "rename-subs!", \$rename_subs, "rename-exports!", \$rename_exports, "rewrite!", \$rewrite, "help", \my $help) or exit 2 6 0 6
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
BranchTrueFalseTotal
if ($help) 1 5 6
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
BranchTrueFalseTotal
unless @ARGV 1 4 5
59 4 ▶die "minify: -o needs exactly one source file\n" if $output && @ARGV > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $output and @ARGV > 1 1 3 4
Condition100%3/3
$output and @ARGV > 1
!ll&&!rl&&r
211
MC/DC100%2/2
$output and @ARGV > 1
$output @ARGV > 1
Truth table100%3/3
A and B
A= $outputB= @ARGV > 1
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $m =~ /\n\z/ 3 0 3
67 3 $m;
68 } @ARGV;
69 3 ▶if ($output) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output) { } 1 2 3
70 1 ▶ open my $fh, '>', $output or die "Cannot write $output: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $output or die "Cannot write ${output}: $!" 1 0 1
71 1 print {$fh} $out[0];
72 1 close $fh;
73 } else {
74 2 print for @out;
75 }
76 __END__
« lib/App/SlimPacker.pm ↑ Summary