« blib/lib/Perl/PrereqScanner/Scanner/TestMore.pm
↑ Summary
blib/lib/Perl/PrereqScanner/Scanner.pm »
| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | package Perl::PrereqScanner::App 1.100; | ||||||||||||||||||||||||||||
| 3 | # ABSTRACT: scan your working dir for likely prereqs | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use File::Find; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use File::Spec::Functions qw{ catdir updir }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use FindBin qw{ $Bin }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use lib catdir( $Bin, updir, 'lib' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use List::Util qw{ max }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Perl::PrereqScanner; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use CPAN::Meta::Requirements (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Getopt::Long qw{ GetOptions }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | my %options; | |||||||||||||||||||||||||||
| 19 | 2 | GetOptions( | |||||||||||||||||||||||||||
| 20 | \%options, | ||||||||||||||||||||||||||||
| 21 | 'combine!', | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | 2 | ▶ | my $combined = $options{combine} && CPAN::Meta::Requirements->new; | ||||||||||||||||||||||||||
|
Condition66%2/3
$options{'combine'} && 'CPAN::Meta::Requirements'->new
MC/DC50%1/2
$options{'combine'} && 'CPAN::Meta::Requirements'->new
$options{'combine'}
'CPAN::Meta::Requirements'->new
Truth table66%2/3
A && B
A= $options{'combine'}B= 'CPAN::Meta::Requirements'->new
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | foreach my $file ( @ARGV ? @ARGV : '.' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 4 | ▶ | -d $file ? scan_dir( $file ) : scan_file( $file ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub scan_dir { | ||||||||||||||||||||||||||
|
Subroutine
scan_dir: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 30 | find( { | ||||||||||||||||||||||||||||
| 31 | no_chdir => 1, | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | wanted => sub { scan_file($_) if /\.(pl|pm|psgi|t)$/ && -f $_; } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
Condition0%0/3
/\.(pl|pm|psgi|t)$/ and -f $_
MC/DC0%0/2
/\.(pl|pm|psgi|t)$/ and -f $_
/\.(pl|pm|psgi|t)$/
-f $_
Truth table0%0/3
A and B
A= /\.(pl|pm|psgi|t)$/B= -f $_
| |||||||||||||||||||||||||||||
| 33 | 0 | }, shift ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 4 | ▶ | sub scan_file { | ||||||||||||||||||||||||||
|
Subroutine
scan_file: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 37 | 4 | my $file = shift; | |||||||||||||||||||||||||||
| 38 | 4 | my $prereqs = Perl::PrereqScanner->new->scan_file($file); | |||||||||||||||||||||||||||
| 39 | 4 | ▶ | if( $options{combine} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 2 | $combined->add_requirements($prereqs); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||
| 43 | 2 | print "* $file\n"; | |||||||||||||||||||||||||||
| 44 | 2 | print_prereqs($prereqs); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | if( $options{combine} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 1 | print_prereqs($combined); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | ▶ | sub print_prereqs { | ||||||||||||||||||||||||||
|
Subroutine
print_prereqs: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 53 | 3 | my $prereqs = shift->as_string_hash; | |||||||||||||||||||||||||||
| 54 | 3 | my $max = max map { length } keys %$prereqs; | |||||||||||||||||||||||||||
| 55 | printf( "%-${max}s = %s\n", $_, $prereqs->{$_} ) | ||||||||||||||||||||||||||||
| 56 | 3 | for sort keys %$prereqs; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | exit; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | #pod =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 62 | #pod | ||||||||||||||||||||||||||||
| 63 | #pod scan_prereqs [--combine] [DIRS|FILES] | ||||||||||||||||||||||||||||
| 64 | #pod | ||||||||||||||||||||||||||||
| 65 | #pod Directories are traversed with L<File::Find> to collect all C<.pl>, C<.pm>, | ||||||||||||||||||||||||||||
| 66 | #pod C<.psgi> and C<.t> files. If no directories or files are specified, the current | ||||||||||||||||||||||||||||
| 67 | #pod working directory is scanned. | ||||||||||||||||||||||||||||
| 68 | #pod | ||||||||||||||||||||||||||||
| 69 | #pod =cut | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||