| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use 5.008005; |
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
use Time::HiRes 1.97 (); |
| 7 |
use Getopt::Long 2.33 (); |
| 8 |
|
| 9 |
=pod |
| 10 |
|
| 11 |
=head1 NAME |
| 12 |
|
| 13 |
cpangraph - Generate dependency chain graphs for CPAN modules |
| 14 |
|
| 15 |
=head1 VERSION |
| 16 |
|
| 17 |
Version 0.12 |
| 18 |
|
| 19 |
=cut |
| 20 |
|
| 21 |
our $VERSION = '0.19'; |
| 22 |
|
| 23 |
use CPANDB (); |
| 24 |
|
| 25 |
# Check params |
| 26 |
my $PERL = undef; |
| 27 |
my $PHASE = undef; |
| 28 |
my $VERBOSE = 0; |
| 29 |
my $RANKDIR = 0; |
| 30 |
my $REVERSE = 0; |
| 31 |
|
| 32 |
=pod |
| 33 |
|
| 34 |
=head1 SYNOPSIS |
| 35 |
|
| 36 |
cpangraph [options] <file> |
| 37 |
|
| 38 |
Options: |
| 39 |
--help display a brief help message |
| 40 |
--perl=VERSION filter those available in Perl core |
| 41 |
--phase=PHASE filter those needed for a phase (e.g., build) |
| 42 |
--rankdir controls the GraphViz 'rankdir' variable |
| 43 |
--reverse graph reverse dependencies (dependents) |
| 44 |
--verbose display additional debugging information |
| 45 |
|
| 46 |
=head1 OPTIONS |
| 47 |
|
| 48 |
=over |
| 49 |
|
| 50 |
=item B<--help> |
| 51 |
|
| 52 |
Prints a brief help message to the standard output and exits. |
| 53 |
|
| 54 |
=item B<--perl>=VERSION |
| 55 |
|
| 56 |
This displays dependencies which have been available in Perl core since |
| 57 |
the given VERSION. It does not currently know if a module has been removed |
| 58 |
from core, but this is an unlikely occurrence. Specify Perl versions in |
| 59 |
the form: |
| 60 |
|
| 61 |
5.008008 # for versions >= 5.8.8 |
| 62 |
5.010 # for versions >= 5.10 |
| 63 |
|
| 64 |
=item B<--phase>=PHASE |
| 65 |
|
| 66 |
This displays dependencies which are needed for a given module's install |
| 67 |
or runtime PHASE. Available phases are: |
| 68 |
|
| 69 |
=over |
| 70 |
|
| 71 |
=item * runtime: required whenever the module is used |
| 72 |
|
| 73 |
=item * build: required to build the module |
| 74 |
|
| 75 |
=item * configure: these are required while preparing the module for |
| 76 |
build |
| 77 |
|
| 78 |
=back |
| 79 |
|
| 80 |
=item B<--rankdir> |
| 81 |
|
| 82 |
In GraphViz, the 'rankdir' attribute controls the direction that the nodes |
| 83 |
are linked together. If set, the graph will use left -> right linking of |
| 84 |
nodes rather than the default up-down linking. |
| 85 |
|
| 86 |
=item B<--reverse> |
| 87 |
|
| 88 |
Create a graph of the reverse dependencies of a package (the packages which |
| 89 |
depend on it, or dependent packages). |
| 90 |
|
| 91 |
=item B<--verbose> |
| 92 |
|
| 93 |
Display extra output useful during debugging. |
| 94 |
|
| 95 |
=back |
| 96 |
|
| 97 |
=cut |
| 98 |
|
| 99 |
=head1 DESCRIPTION |
| 100 |
|
| 101 |
B<This script> will use the CPAN Database to build a graph of a package's |
| 102 |
dependencies or reverse dependencies (dependent packages). |
| 103 |
|
| 104 |
=cut |
| 105 |
|
| 106 |
Getopt::Long::GetOptions( |
| 107 |
'perl=s' => \$PERL, |
| 108 |
'phase=s' => \$PHASE, |
| 109 |
'verbose' => \$VERBOSE, |
| 110 |
'rankdir' => \$RANKDIR, |
| 111 |
'reverse' => \$REVERSE, |
| 112 |
) or die "Failed to parse options"; |
| 113 |
|
| 114 |
# Find the distribution |
| 115 |
my $name = shift @ARGV; |
| 116 |
unless ( $name ) { |
| 117 |
print "Did not provide a distribution name\n"; |
| 118 |
exit(0); |
| 119 |
} |
| 120 |
|
| 121 |
# Load the database and fine the distribution |
| 122 |
CPANDB->import( { |
| 123 |
show_progress => $VERBOSE, |
| 124 |
} ); |
| 125 |
my $dist = CPANDB->distribution($name); |
| 126 |
|
| 127 |
# Determine the graph file name |
| 128 |
my $file = $name; |
| 129 |
if ( $PHASE ) { |
| 130 |
$file .= '-' . $PHASE; |
| 131 |
} |
| 132 |
if ( $PERL ) { |
| 133 |
$file .= '-' . $PERL; |
| 134 |
} |
| 135 |
|
| 136 |
# Generate the graph |
| 137 |
my $method = $REVERSE |
| 138 |
? 'dependants_graphviz' |
| 139 |
: 'dependency_graphviz'; |
| 140 |
$dist->$method( |
| 141 |
perl => $PERL, |
| 142 |
phase => $PHASE, |
| 143 |
rankdir => $RANKDIR, |
| 144 |
)->as_svg("$file.svg"); |
| 145 |
|
| 146 |
=pod |
| 147 |
|
| 148 |
=head1 AUTHOR |
| 149 |
|
| 150 |
Adam Kennedy E<lt>[email protected]<gt> |
| 151 |
|
| 152 |
=head1 SUPPORT |
| 153 |
|
| 154 |
For support details, please look at C<perldoc CPANDB> and use the |
| 155 |
corresponding support methods. |
| 156 |
|
| 157 |
=head1 LICENSE |
| 158 |
|
| 159 |
This has the same copyright and licensing terms as L<CPANDB>. |
| 160 |
|
| 161 |
=cut |