| 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
| |||||||||||||||
| 27 | 0 | say( $usage->text ); | |||||||||||||
| 28 | 0 | exit; | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 39 | ▶ | if ( $opt->version ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 61 | 5 | next; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 22 | ▶ | if ( $code > 0 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 71 | |||||||||||||||
| 72 | 19 | exit($exit_code); | |||||||||||||
| 73 | |||||||||||||||
| 74 | # PODNAME: perlvars | ||||||||||||||
| 75 | # ABSTRACT: A command line utility for detecting unused Perl variables | ||||||||||||||
| 76 | |||||||||||||||
| 77 | __END__ | ||||||||||||||