| 1 | #!/usr/bin/env perl | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use App::PrereqGrapher; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | my $app = App::PrereqGrapher->new_with_options; | |
| 7 | |||
| 8 | 1 | $app->generate_graph(@ARGV); | |
| 9 | |||
| 10 | 1 | exit 0; | |
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | prereq-grapher - generate dependency graph for perl module or source | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | prereq-grapher [options] Foo::Bar .. Foo::Baz | ||
| 19 | |||
| 20 | Options: | ||
| 21 | -o <file> The file to write the graph into | ||
| 22 | -d <int> Stop recursing at the specified depth | ||
| 23 | -t <seconds> Timeout for when generating SVG or HTML output | ||
| 24 | -nc Don't include core modules in dependency graph | ||
| 25 | -nrc Show core modules, but not their dependencies | ||
| 26 | -dot Generate graph in dot format (used by GraphViz) | ||
| 27 | -svg Generate graph as Scalable Vector Graphics | ||
| 28 | -html Generate graph as HTML | ||
| 29 | -gml Generate graph as GraphML | ||
| 30 | -vcg Generate graph in VCG format | ||
| 31 | -verbose Display verbose messages as we run | ||
| 32 | -h --help This help | ||
| 33 | |||
| 34 | =head1 DESCRIPTION | ||
| 35 | |||
| 36 | B<prereq-grapher> parses perl source and looks for prerequisites, | ||
| 37 | such as modules that are C<use>'d or C<require>'d. | ||
| 38 | All of those modules are then parsed in turn, | ||
| 39 | looking for I<their> dependencies. | ||
| 40 | |||
| 41 | Once all files have been parsed, B<prereq-grapher> will write out | ||
| 42 | the dependency graph in one of the five formats supported. | ||
| 43 | |||
| 44 | The simplest way to run B<prereq-grapher> is just giving a module name: | ||
| 45 | |||
| 46 | % prereq-grapher Module::Path | ||
| 47 | 6 modules processed. Graph written to dependencies.dot | ||
| 48 | |||
| 49 | By default B<prereq-grapher> generates the dependency graph in C<dot> format, | ||
| 50 | and writes it to a file called C<dependencies.dot>. | ||
| 51 | You can explicitly specify the output format and filename: | ||
| 52 | |||
| 53 | % prereq-grapher -svg -o class-inspector-path.svg Class::Inspector | ||
| 54 | 9 modules processed. Graph written to class-inspector.svg | ||
| 55 | |||
| 56 | If the complete dependency graph is very large, | ||
| 57 | it can be hard to get your head around it. | ||
| 58 | In this case you could start off generating the first few levels of dependencies, | ||
| 59 | using the B<-depth> (or B<-d>) option: | ||
| 60 | |||
| 61 | % prereq-grapher App::PrereqGrapher | ||
| 62 | 305 modules processed. Graph written to dependencies.dot | ||
| 63 | |||
| 64 | % prereq-grapher -depth 2 App::PrereqGrapher | ||
| 65 | 10 modules processed. Graph written to dependencies.dot | ||
| 66 | |||
| 67 | =head1 OPTIONS | ||
| 68 | |||
| 69 | =over 4 | ||
| 70 | |||
| 71 | =item B<-o> E<lt>fileE<gt> | B<-output-file> E<lt>fileE<gt> | ||
| 72 | |||
| 73 | The name of the file that the dependency graph should be written to. | ||
| 74 | If not specified, B<prereq-grapher> will write the graph in a file | ||
| 75 | called C<dependencies>, and the extension will indicate the format | ||
| 76 | (dot, svg, html, gml, or vcg). | ||
| 77 | |||
| 78 | =item B<-d N> | B<-depth N> | ||
| 79 | |||
| 80 | Generate the dependency graph to a depth of no more than N links. | ||
| 81 | |||
| 82 | =item B<-r T> | B<-timeout T> | ||
| 83 | |||
| 84 | Specifies the timeout that should be passed to Graph::Easy when | ||
| 85 | generating the output graph. Mainly relevant for SVG and HTML formats. | ||
| 86 | |||
| 87 | =item B<-nc> | B<-no-core> | ||
| 88 | |||
| 89 | Don't include any core dependencies in the generated dependency graph. | ||
| 90 | |||
| 91 | =item B<-nrc> | B<-no-recurse-core> | ||
| 92 | |||
| 93 | Include core modules in the output, but don't include any of their dependencies. | ||
| 94 | |||
| 95 | =item B<-dot> | ||
| 96 | |||
| 97 | Generate the dependency graph in the Dot format supported by the GraphViz tools. | ||
| 98 | |||
| 99 | =item B<-svg> | ||
| 100 | |||
| 101 | Generate the dependency graph as Scalable Vector Graphics. | ||
| 102 | |||
| 103 | =item B<-html> | ||
| 104 | |||
| 105 | Generate the dependency graph as an HTML file with embedded CSS. | ||
| 106 | Note: I haven't got this to work yet, but it's one of the output formats | ||
| 107 | supported by L<Graph::Easy>. | ||
| 108 | |||
| 109 | =item B<-v> | B<-verbose> | ||
| 110 | |||
| 111 | Display verbose messages as the script runs. | ||
| 112 | If a module is use'd or require'd, but not installed locally, | ||
| 113 | then by default it will be silently ignored. | ||
| 114 | In verbose mode you'll hear about all such modules. | ||
| 115 | |||
| 116 | =back | ||
| 117 | |||
| 118 | =head1 SEE ALSO | ||
| 119 | |||
| 120 | For the B<dot> format, see L<http://www.graphviz.org>. | ||
| 121 | There are graphical tools for viewing direct graphs, or you can use the C<dot> | ||
| 122 | program on the command-line to generate an image, postscript, or many other things besides. | ||
| 123 | |||
| 124 | For SVG, you could look at the L<W3C page on SVG|http://www.w3.org/Graphics/SVG/>, | ||
| 125 | but probably more useful is the | ||
| 126 | L<Wikipedia page on SVG|http://en.wikipedia.org/wiki/Scalable_Vector_Graphics>. | ||
| 127 | |||
| 128 | For GraphML (the B<gml> export format), | ||
| 129 | see <the GraphML home page|http://graphml.graphdrawing.org>. | ||
| 130 | |||
| 131 | I haven't been able to get the HTML version to work for any dependency graph I've tried. | ||
| 132 | |||
| 133 | For VCG, see L<The VCG home page|http://rw4.cs.uni-sb.de/~sander/html/gsvcg1.html>. | ||
| 134 | |||
| 135 | The functionality for B<prereq-grapher> is provided by L<App::PrereqGrapher>, | ||
| 136 | which in turn builds on L<Perl::PrereqScanner> and L<Graph::Easy>. | ||
| 137 | |||
| 138 | =head1 AUTHOR | ||
| 139 | |||
| 140 | Neil Bowers E<lt>neilb@cpan.orgE<gt> | ||
| 141 | |||
| 142 | =head1 COPYRIGHT AND LICENSE | ||
| 143 | |||
| 144 | This software is copyright (c) 2012 by Neil Bowers. | ||
| 145 | |||
| 146 | This is free software; you can redistribute it and/or modify it under | ||
| 147 | the same terms as the Perl 5 programming language system itself. | ||
| 148 | |||
| 149 | =cut | ||
| 150 | |||