1: #!/usr/bin/perl 2: # Author : Valter Mazzola, txian@hotmail.com, Italy 3: # Date 25/May/2000, Local time 01:00 AM. 4: 5: # Purpose: 6: # ---> Generate a Graph-ical call tree for your *.pm perl module files. 7: # gra.pl assume that: 8: # 1- you have defined sub(s) with 'sub myfunc {' with 'sub' at the beginning of line. 9: # 2- you call your sub with the '&', i.e. &my_sub (); 10: 11: # The code isn't clean nor perfect ! I've made it in 30 min (including testing) ! 12: 13: # usage: 14: # 1) generate the .dot text graph file definition 15: # perl gra.pl *.pm > myfile.dot 16: # 2) generate the graph using 'dot' executable ( http://www.research.att.com/sw/tools/graphviz/ ) 17: # dot -Tps myfile.dot -o myfile.ps 18: # 3) display the graph 19: # ghostview myfile.ps (choose BBox format) 20: 21: while (<>){ 22: if (/^sub\s+(.*?)\s*\{/){ 23: $cur_sub=$1; 24: } 25: if (/\&([\d\w_]+)\s*\(/){ 26: $c_sub = $1; 27: $n = 0; 28: foreach $k (@{$called_subs{$cur_sub}}) { 29: if ($c_sub eq $k){ 30: $n = 1; 31: last; 32: } 33: } 34: if ($n == 0) { 35: push @{$called_subs{$cur_sub}}, $c_sub; 36: } 37: } 38: } 39: 40: print "digraph G {\n"; 41: print " ratio=auto;\n"; 42: 43: foreach $k (keys(%called_subs)){ 44: $ref_arr = $called_subs{$k}; 45: if (ref($ref_arr)) { 46: foreach $y (@{$ref_arr}){ 47: print " $k -> $y;\n"; 48: } 49: } 50: } 51: 52: print "}\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Generate a Graph-ical call tree for your *.pm perl modules
by merlyn (Sage) on May 25, 2000 at 09:29 UTC | |
RE: Generate a Graph-ical call tree for your *.pm perl modules
by johannz (Hermit) on May 25, 2000 at 20:36 UTC | |
RE: Generate a Graph-ical call tree for your *.pm perl modules
by ZZamboni (Curate) on May 25, 2000 at 04:33 UTC | |
Re: Generate a Graph-ical call tree for your *.pm perl modules
by Anonymous Monk on May 07, 2003 at 00:17 UTC | |
Re: Generate a Graph-ical call tree for your *.pm perl modules
by RobG (Initiate) on May 24, 2012 at 07:11 UTC |
Back to
Craft