Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Analyzing a Perl application

by szabgab (Priest)
on Jan 31, 2011 at 12:35 UTC ( #885259=perlquestion: print w/replies, xml ) Need Help??
szabgab has asked for the wisdom of the Perl Monks concerning the following question:

I am not sure exactly what am I looking for so let me just think aloud. Meditate about this.

I need some tool that will help me analyze the source code of an application written in Perl.

I think some of the analyzes should based on Perl::Critic but I'd probably also like to find duplicate pieces of code. Copies of functions or smaller parts of code. Cases where the copies are not 100% identical but that are very similar.

I'd like to be able to draw a map of the class hierarchy and where is each class, method or function being used.

I am sure there are other ways to analyze code. Ideas?

Replies are listed 'Best First'.
Re: Analyzing a Perl application
by Corion (Pope) on Jan 31, 2011 at 13:03 UTC

    There is B::Xref, which claims to create cross-reference sections.

    For class inheritance, I'm sure there is a module that lists you the tree, as Ovid uses fancy graphviz output in the paper, and I doubt he created that manually.

Re: Analyzing a Perl application
by andreas1234567 (Vicar) on Jan 31, 2011 at 13:55 UTC
    I'd probably also like to find duplicate pieces of code.
    You could hash all code lines and compare la Eric Raymond.

    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
Re: Analyzing a Perl application
by sundialsvc4 (Abbot) on Jan 31, 2011 at 21:28 UTC

    This is, un-fortunately, one of those cases where “TMTOWTDI” can turn-around and bite you in the (!).   There are many syntactically-different ways to express the same meaning in terms of source-code, and when you say, “are very similar,” you unfortunately (probably) mean, “means, or does, the same thing.”   And that kind of analysis ... which BTW I have done many, many times ... requires “the human eye.”

    I happen to have more-than-trivial knowledge of the arcane arts of “source code analysis,” having worked for an early-90’s startup that tried (in vain...) to do this sort of thing with COBOL.   (They went public anyway, then of course went bust.)   You can map out data-dependencies and control flows (as I have myself done recently, in another Meditation), but you cannot discern meaning.

    Certainly, you can automatically scan source-code to build up a data-dictionary and a code-dictionary ... and this, for an app that might involve many hundreds or even thousands of source-components, can certainly be useful.   These undertakings very quickly outstrip the limits of human visualization, even for the most spectacular of totally self-absorbed nerds.

      Finding code snippets that mean the same even though written differently would be of course super awesome but for now I would be happy to locate instances of "copy-paste development".
Re: Analyzing a Perl application
by planetscape (Chancellor) on Feb 01, 2011 at 11:43 UTC
Re: Analyzing a Perl application
by Jeppe (Monk) on Feb 01, 2011 at 14:38 UTC
    I've found that running the code through perltidy (using the same format) is a good idea, it will transform code to be uniformly formatted. That way, whitespace differences etc are eliminated as a source of difference between two pieces of code. Obviously, you should run the perltidy script before any other systems that searches your codebase for duplicate code or near-duplicate code. Using perltidy will improve the false-positive rate of the other systems.

    (You can even enforce a uniform coding format by using perltidy with the available hooks in source control products, but that's a different subject)

Re: Analyzing a Perl application
by repellent (Priest) on Feb 06, 2011 at 19:45 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://885259]
Approved by Arunbear
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2018-06-20 14:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.