Debian Codegraph @

bin/scan_prereqs

raw
1 #!/usr/bin/perl
2 package Perl::PrereqScanner::App 1.100;
3 # ABSTRACT: scan your working dir for likely prereqs
4
5 use strict;
6 use warnings;
7
8 use File::Find;
9 use File::Spec::Functions qw{ catdir updir };
10 use FindBin qw{ $Bin };
11 use lib catdir( $Bin, updir, 'lib' );
12
13 use List::Util qw{ max };
14 use Perl::PrereqScanner;
15 use CPAN::Meta::Requirements ();
16
17 use Getopt::Long qw{ GetOptions };
18 my %options;
19 GetOptions(
20 \%options,
21 'combine!',
22 );
23 my $combined = $options{combine} && CPAN::Meta::Requirements->new;
24
25 foreach my $file ( @ARGV ? @ARGV : '.' ) {
26 -d $file ? scan_dir( $file ) : scan_file( $file );
27 }
28
29 sub scan_dir {
30 find( {
31 no_chdir => 1,
32 wanted => sub { scan_file($_) if /\.(pl|pm|psgi|t)$/ && -f $_; }
33 }, shift );
34 }
35
36 sub scan_file {
37 my $file = shift;
38 my $prereqs = Perl::PrereqScanner->new->scan_file($file);
39 if( $options{combine} ){
40 $combined->add_requirements($prereqs);
41 }
42 else {
43 print "* $file\n";
44 print_prereqs($prereqs);
45 }
46 }
47
48 if( $options{combine} ){
49 print_prereqs($combined);
50 }
51
52 sub print_prereqs {
53 my $prereqs = shift->as_string_hash;
54 my $max = max map { length } keys %$prereqs;
55 printf( "%-${max}s = %s\n", $_, $prereqs->{$_} )
56 for sort keys %$prereqs;
57 }
58
59 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__
72
73 =pod
74
75 =encoding UTF-8
76
77 =head1 NAME
78
79 Perl::PrereqScanner::App - scan your working dir for likely prereqs
80
81 =head1 VERSION
82
83 version 1.100
84
85 =head1 SYNOPSIS
86
87 scan_prereqs [--combine] [DIRS|FILES]
88
89 Directories are traversed with L<File::Find> to collect all C<.pl>, C<.pm>,
90 C<.psgi> and C<.t> files. If no directories or files are specified, the current
91 working directory is scanned.
92
93 =head1 PERL VERSION
94
95 This library should run on perls released even a long time ago. It should work
96 on any version of perl released in the last five years.
97
98 Although it may work on older versions of perl, no guarantee is made that the
99 minimum required version will not be increased. The version may be increased
100 for any reason, and there is no promise that patches will be accepted to lower
101 the minimum required perl.
102
103 =head1 AUTHORS
104
105 =over 4
106
107 =item *
108
109 Jerome Quelin
110
111 =item *
112
113 Ricardo Signes <[email protected]>
114
115 =back
116
117 =head1 COPYRIGHT AND LICENSE
118
119 This software is copyright (c) 2009 by Jerome Quelin.
120
121 This is free software; you can redistribute it and/or modify it under
122 the same terms as the Perl 5 programming language system itself.
123
124 =cut