rapide has asked for the wisdom of the Perl Monks concerning the following question:

Ive worked on a project now for quite some time now. It has evolved to a lot of files and directories which is quite a mess, it may seem like. So I was considering re factoring parts of the code but as I do not know how or where to start I need to build a diagram of the dependencies to get a better overview. So my question is really; Is there a tool or script out there that can take Perl files and build up a list of which modules "requires" other modules or "uses" other packages ?
  • Comment on Is there a tool or script to build a dependency list between modules?

Replies are listed 'Best First'.
Re: Is there a tool or script to build a dependency list between modules?
by almut (Canon) on Jan 23, 2009 at 22:52 UTC
Re: Is there a tool or script to build a dependency list between modules?
by planetscape (Chancellor) on Jan 23, 2009 at 23:13 UTC
Re: Is there a tool or script to build a dependency list between modules?
by ikegami (Patriarch) on Jan 23, 2009 at 22:45 UTC
    The hard part is identifying the modules, so build something using the code from Devel::Modlist?

    Update: Bah, it actually runs the code.

Re: Is there a tool or script to build a dependency list between modules?
by Khen1950fx (Canon) on Jan 24, 2009 at 00:26 UTC
    I use this little script here.
Re: Is there a tool or script to build a dependency list between modules?
by ELISHEVA (Prior) on Jan 24, 2009 at 18:54 UTC

    I know this sounds like a lot of work, but I would strongly recommend a manual walk-through. Keep pen and paper or a simple text editor on the side and record what you learn.

    Usually, out and and out dependencies are not the main issue in planning a refactoring. The dependencies are generally a by product of well factored code, not the starting point.

    The thing to look for are:

    • algorithms that are the same except for data or small variations in logic that can be replaced with well chosen boolean flags, op codes, or code references - these can be consolidated into a single function with some data parameters. Or if you don't like data parameters and you are comfortable with closures or functor classes, you may want to replace these closely related functions with functor objects or a function that generates closures.
    • groups of interrelated functions that are conceptually similar. If you have two or more ways of implementing the functional cluster, you might want to consider refactoring your code into a class for each functional group. Then create a subclass for each separate implementation of that functional group.
    • combinations of functional groups - once you start grouping your functions into conceptual groups, you may start noticing that some of your code takes implementation A from group 1, implementation B from group 2. Some other code takes implementation X from group 1 and Y from group 2. You might want to consider re-factoring this code into composition classes - e.g. a class whose constructor takes two parameters - an object that implements group 1 functionality and an object that implements group 2 functionality.
    Best of luck, beth