0: #!/usr/bin/perl
1: # Author : Valter Mazzola, txian@hotmail.com, Italy
2: # Date 25/May/2000, Local time 01:00 AM.
3:
4: # Purpose:
5: # ---> Generate a Graph-ical call tree for your *.pm perl module files.
6: # gra.pl assume that:
7: # 1- you have defined sub(s) with 'sub myfunc {' with 'sub' at the beginning of line.
8: # 2- you call your sub with the '&', i.e. &my_sub ();
9:
10: # The code isn't clean nor perfect ! I've made it in 30 min (including testing) !
11:
12: # usage:
13: # 1) generate the .dot text graph file definition
14: # perl gra.pl *.pm > myfile.dot
15: # 2) generate the graph using 'dot' executable ( http://www.research.att.com/sw/tools/graphviz/ )
16: # dot -Tps myfile.dot -o myfile.ps
17: # 3) display the graph
18: # ghostview myfile.ps (choose BBox format)
19:
20: while (<>){
21: if (/^sub\s+(.*?)\s*\{/){
22: $cur_sub=$1;
23: }
24: if (/\&([\d\w_]+)\s*\(/){
25: $c_sub = $1;
26: $n = 0;
27: foreach $k (@{$called_subs{$cur_sub}}) {
28: if ($c_sub eq $k){
29: $n = 1;
30: last;
31: }
32: }
33: if ($n == 0) {
34: push @{$called_subs{$cur_sub}}, $c_sub;
35: }
36: }
37: }
38:
39: print "digraph G {\n";
40: print " ratio=auto;\n";
41:
42: foreach $k (keys(%called_subs)){
43: $ref_arr = $called_subs{$k};
44: if (ref($ref_arr)) {
45: foreach $y (@{$ref_arr}){
46: print " $k -> $y;\n";
47: }
48: }
49: }
50:
51: print "}\n";
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|