script/perlvars

filter: Statementstmt 87.5% 35 / 40 Branchbran 88.8% 16 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 88.8% 56 / 63 CC 1 SCAR 0.0
CC
1
Cov
88%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« test-data/scripts/lib/Local/PkgNoisy.pm ↑ Summary test-data/scripts/lib/Local/PkgSkip.pm »
1 #!perl
2  
3 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 39 ▶use App::perlvars ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 39 ▶use Getopt::Long::Descriptive qw( describe_options );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 39 my ( $opt, $usage ) = describe_options(
11 'perlvars %o file',
12 [ 'ignore-file|i=s', 'A file containing an ignore list', ],
13 [
14 'scripts',
15 'Also lint package-less files (e.g. .t and .pl scripts) by wrapping them in a synthetic package',
16 ],
17 [],
18 [ 'help', 'print usage message and exit', { shortcircuit => 1 } ],
19 [
20 'verbose-help', 'print verbose usage message and exit',
21 { shortcircuit => 1 }
22 ],
23 [ 'version', 'print version and exit', { shortcircuit => 1 } ],
24 );
25  
26 39 ▶if ( $opt->help ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->help) 0 39 39
27 0 say( $usage->text );
28 0 exit;
29 }
30  
31 39 ▶if ( $opt->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->version) 1 38 39
32 1 say "perlvars $App::perlvars::VERSION";
33 1 exit;
34 }
35  
36 38 my $exit_code = 0;
37  
38 38 my @files = @ARGV;
39  
40 38 ▶unless (@files) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@files) 0 38 38
41 0 require Pod::Usage;
42 0 say $usage->text;
43 0 Pod::Usage::pod2usage();
44 }
45  
46 38 ▶my $vars = App::perlvars->new(
Branch: 2 branches
BranchTrueFalseTotal
$opt->ignore_file ? : 5 33 38
$opt->scripts ? : 19 19 38
47 ( $opt->ignore_file ? ( ignore_file => $opt->ignore_file ) : () ),
48 ( $opt->scripts ? ( lint_scripts => 1 ) : () ),
49 );
50  
51 38 for my $file (@files) {
52 46 say $file;
53 46 my ( $code, $error_message, @notes ) = $vars->validate_file($file);
54  
55 27 ▶ if ($error_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error_message) 5 22 27
56 5 say STDERR $error_message;
57  
58 # A per-file problem (not found, unparseable, no package) must not
59 # abort the run: record any failure and carry on to the next file.
60 5 ▶ $exit_code = $code if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 4 1 5
61 5 next;
62 }
63  
64 22 ▶ if ( $code > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code > 0) 7 15 22
65 7 $exit_code = $code;
66 7 say STDERR $_ for @notes;
67 }
68 }
69  
70 19 ▶say 'All files ok' unless $exit_code;
Branch: 1 branch
BranchTrueFalseTotal
unless $exit_code 10 9 19
71  
72 19 exit($exit_code);
73  
74 # PODNAME: perlvars
75 # ABSTRACT: A command line utility for detecting unused Perl variables
76  
77 __END__
« test-data/scripts/lib/Local/PkgNoisy.pm ↑ Summary test-data/scripts/lib/Local/PkgSkip.pm »