se on example: http://www.ffnn.nl/pages/articles/media/uml-diagrams-using-graphviz-dot.php my $type = $ARGV[1]; my $file = $ARGV[0]; my $name = $file; $name=~s/\.(.*)//; my $HEADER = "digraph G { fontname = \"Bitstream Vera Sans\" fontsize = 8 node [ fontname = \"Bitstream Vera Sans\" fontsize = 8 shape = \"none\" ] edge [ fontname = \"Bitstream Vera Sans\" fontsize = 8 ] "; my $FOOTER = " }"; open (FILE,$ARGV[0]) or die "$ARGV[0] file not found"; my $entity; my $mode = "declaration"; my $open = 0; my $decl = ""; my $connec = ""; my $funct; my $vars; my $packaged = 0; my $comment = ""; my $commentconnec = "\nedge [\narrowhead = \"none\"\n]\n"; my $class; while (){ chomp(); if(/^#/){ next; } if(/\/\/(.+)/){ $comment.="\\n" if($comment ne "") ; $comment .= $1; $comment=~s/"/''/; next; } if(/\[(.*?)\]/ && $mode eq "declaration"){ if($open){ $decl .= $funct.$vars; $decl .= ">\n\t\t]\n"; if($comment){ $decl .= "\t\t\"comment_for_$class\" [\nshape=note,label=\"$comment\",style=filled,fillcolor=yellow];\n"; $commentconnec.= "\n$class -> \"comment_for_$class\" \n"; $comment = ""; } $funct = ""; $vars = ""; if($packaged){ $packaged = 0; $decl .="\n\t}\n"; } } $class = $1; if($1=~/(.+)::(.+)/){ $class = $2; $decl .= "\tsubgraph cluster".$1." {\n\t\tlabel= <".$1.">\n"; $decl .= "\t\tbgcolor= \"#EFEFEF\"\n"; $packaged = 1; } $open = 1; $decl.="\t\t".$class."[\n"; $decl .= "\t\t\t label = <"; } elsif(/(.*\(.*\).*)/){ $funct.="" } elsif(/^\+|^\-/) { $vars .= ""; } #connections if(/(.*?)(\-+)>(.*)/){ if($open){ #close opened declarations before $decl .= $funct.$vars."
$class
$1
".$_."
"; $decl .= ">\n\t\t]\n"; if($comment){ $decl .= "\t\t\"comment_for_$class\" [\nshape=note,label=\"$comment\",style=filled,fillcolor=yellow];\n"; $commentconnec.= "\n$class -> \"comment_for_$class\" \n"; $comment = ""; } $funct = ""; $vars = ""; $open = 0; if($packaged){ $packaged = 0; $decl .="\n\t}\n"; } } my $add = ""; if(length($2)>1){ $add = "[style=dotted]"; } $mode = "connections"; $connec.="$1 -> $3 ".$add."\n"; } } #close last if($open){ #$decl .= $funct."|".$vars; $decl .= ">\n\t\t]\n"; if($comment){ $decl .= "\t\t\"comment_for_$class\" [\nshape=note,label=\"$comment\",style=filled,fillcolor=yellow];\n"; $commentconnec.= "\n$class -> \"comment_for_$class\" \n"; $comment = ""; } if($packaged){ $packaged = 0; $decl .="\n\t\t}\n"; } } open (TMP,">/tmp/digraph".$ARGV[0]); print TMP $HEADER; print TMP $decl; print TMP $connec; print TMP $commentconnec; print TMP $FOOTER; close(FILE); close(TMP); `cat /tmp/digraph$ARGV[0] | dot -T$type -o $name.$type && rm -f /tmp/digraph$ARGV[0]`; if($type eq "png"){ `eog $name.$type` } elsif($type eq "pdf"){ `evince $name.$type` }