Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I've inherited some perl code that traverses several source code files with very little documentation. I was hoping that there might be a tool that would reverse engineer the code and would create a flow diagram of the system. Anyone heard of such a beast? Any recommendations short of walking through the code line by line? The code doesn't currently work and they want me to get it working.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Reverse Engineering Perl Tool?
by mikfire (Deacon) on Dec 08, 2000 at 19:55 UTC | |
Failing all of that, I will offer the following two toys. They are not perfect - they may not catch everything - but they have worked quite well for me.
First ToyThis one is a bit strange. It was originally designed to help me update my POD. It crawls through a bit of source and attempts to extract every time a return is called and the context in which it is called. I have modified it slightly so it would not bother parsing the pod in the second loop and instead print to screen. It is a little raw - I am the only one who uses it and I know how it is to be called :)
Second ToyThis next one needs at least two parameters. The first arg is the source file. This file will be searched for all subroutine declarations. It will then search through all the remaining files on the command line, looking for those subroutines. When it finds one, it will print the name of the file, the line number and the call itself. It is heavily oriented towards OO perl and it does require perl 5.5 or better - I am something of a compiled regex junky.< mikfire | [reply] [d/l] [select] |
Re: Reverse Engineering Perl Tool?
by clemburg (Curate) on Dec 08, 2000 at 13:57 UTC | |
Hm. This might be too low-level, but you might want to have a look a the following:
Christian Lemburg | [reply] |
Re: Reverse Engineering Perl Tool?
by BlueLines (Hermit) on Dec 08, 2000 at 09:38 UTC | |
xemacs your.program.here.pl Seriously, if the code baffles you that much, you should use the perl debugger. There's a node discussing its usage here. Also make sure that you are using the -w switch and that you are using strict. If the code is this sloppy, then there's bound to be errors in it, and these options will help you debug the errors more quickly. Text highlighting and indentation make code more understandable. Use an editor like Xemacs or VIM to reformat the code into more readable pieces. Both of these editors are available for all *nix and Win32 systems. And if there's C/C++/XS stuff involved, check out strace(1), which exists for most *nix systems, as well as NT. BlueLines Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary. | [reply] [d/l] [select] |
Re: Reverse Engineering Perl Tool?
by quidity (Pilgrim) on Dec 08, 2000 at 16:53 UTC | |
You might want to use Deparse to show you the reduced syntax, this will produce slightly prettier output, which might help you a little.
When run through Deparse:
As you can see, some bits get clearer, while others get a little more murky, but it's a useful tool. | [reply] [d/l] [select] |
(bbq) Re: Reverse Engineering Perl Tool?
by BBQ (Curate) on Dec 08, 2000 at 12:48 UTC | |
I am particular to the bells and whistles for debugging, but that's just me. :) #!/home/bbq/bin/perl # Trust no1! | [reply] |
Re: Reverse Engineering Perl Tool?
by snellm (Monk) on Dec 08, 2000 at 14:34 UTC | |
| [reply] |
Back to
Seekers of Perl Wisdom