I needed some code to trawl through a directory tree parsing perl
modules and scripts to determine their dependencies.

The closest existing CPAN code was Module::Dependency but it fell short
of what I needed. The original author (P Kent) has passed over
maintenance to me. My latest release is:

  file: $CPAN/authors/id/T/TI/TIMB/Module-Dependency-1.84.tar.gz
  size: 52161 bytes
   md5: 90a83b2aee39f5d25060ebdb6cc3105d

With the changes I've made I've pretty much 'scratched my own itch'
for the time being. (Most recently with a completely new query
script - docs appended below.) But the core code is still basically as
it was when I came to it.

I'm posting this here to see if anyone would like to contribute to it.
The code is in subversion on perl.org and I'll happily give write
access to anyone interested.

Some random things I'd like to see done:

 - make items be real objects with methods etc
 - use overloading to stringify to $obj->{key}
 - move some pmd_dump.pl subs into object methods
 - abstract the modules and give them proper APIs
 - move to using Sqlite with a proper schema
        for example to handle multiple packages per file,
        not to mention supporting arbitrary queries
 - Look at using Graph::Easy to rewrite/replace Module::Dependency::Grapher.

Tim.

=head1 NAME

pmd_dump.pl - Query and print Module::Dependency info

=head1 SYNOPSIS

    pmd_dump.pl [options] object-patterns

object-patterns can be:

    f=S    - Select objects where field f equals string S
    f=~R   - Select objects where field f matches regex R
    S$     - Same as filename=~S$ to match by file suffix
    S      - Same as key=S

For example:

    package=Foo::Bar         - that specific package
    package=~^Foo::          - all packages that start with Foo::
    filename=~sub/dir/path   - everything with that path in the filename
    filename=~'\.pm$'        - all modules
    restart.pl$              - all files with names ending in restart.pl
    foo                      - same as key=foo

Fields available are:

    filename         - "dir/subdir/foo.pl"
    package          - "strict"
    key              - same as package for packages, or filename for other files
    filerootdir      - "/abs/path"
    depends_on       - "Carp strict Foo::Bar"
    depended_upon_by - "Other::Module dir/subdir/foo.pl dir2/bar.pl 
Another:Module"

Selected objects can be augmented using:

    -P=N   Also pre-select N levels of parent objects
    -C=N   Also pre-select N levels of child objects

Then filtered:

    -F=P   Filter OUT objects matching the object-pattern P
    -S=P   Only SELECT objects matching the object-pattern P

Then merged:

    -M     Merge data for selected objects into a single pseudo-object.
           Removes internally resolved dependencies.
           Handy to see all external dependencies of a group of files.
           The -P and -C flags are typically only useful with -M.

Then modified:

    -D     Delete dependencies on modules which weren't indexed but can
           be found in @INC

Then dumped:

    -f=f1,f2,... - only dump these fields (otherwise all)

And for each one dumped:

    -p=N   Recurse to show N levels of indented parent objects first
    -c=N   Recurse to show N levels of indented child objects after
    -i=S   Use S as the indent string (default is a tab)
    -u     Unique - only show a child or parent once
    -k     Don't show key in header, just the fieldname
    -h     Don't show header (like grep -h), used with -f=fieldname
    -s     sort by name
    -r=P   Show the relationship between the item and those matching P

Other options:

    -help Displays this help
    -t Displays tracing messages
    -o the location of the datafile (default is /var/tmp/dependence/unified.dat)
    -r State the relationship, if any, between item1 and item2 - both may be 
scripts or modules.

=head1 EXAMPLE

    pmd_dump.pl -o ./unified.dat Module::Dependency::Info

Select and merge everything in the database (which removes internally resolved
dependencies) and list the names of all unresolved packages:

    pmd_dump.pl -f=depends_on -h -M ''

Do the same but feed the results back into pmd_dump.pl to get details of what
depends on those unresolved items:

    pmd_dump.pl -f=depended_upon_by `pmd_dump.pl -f=depends_on -h -M ''` | less 
-S

=cut


Reply via email to