NAME

umlclass.pl - Utility to generate UML class diagrams from Perl source or runtime

SYNOPSIS

DESCRIPTION

This is a simple command-line frontend for the UML::Class::Simple module.

I'll illustrate the usage of this tool via some real-world examples.

Draw Stevan's Moose

$ umlclass.pl -M Moose -o samples/moose_small.png -p "^(Class::MOP|Moose::)" -s 4x8

This command will generate a simple class diagram in PNG format for the Moose module with classes having names matching the regex "^(Class::MOP|Moose::)". The image's width is 4 inches while its height is 8 inches.

We need the -M option here since umlclass.pl needs to preload Moose into the memory so as to inspect it at runtime.

The graphical output is given below:

(See also http://perlcabal.org/agent/images/moose_small.png.)

Yes, the image above looks very fuzzy since the whole stuff is huge. If you strip the -s option, then the resulting image will enlarge automatically:

$ umlclass.pl -M Moose -o samples/moose_big.png -p "^(Class::MOP|Moose::)"

The image obtained is really really large, I won't show it here, but you can browse it in your favorite picture browser from http://perlcabal.org/agent/images/moose_big.png.

Before trying out these commands yourself, please make sure that you have Moose already installed. (It's also on CPAN, btw.)

Draw Alias's PPI

$ umlclass.pl -M PPI -o samples/ppi_small.png -p "^PPI::" -s 10x10

(See also http://perlcabal.org/agent/images/ppi_small.png.)

Or the full-size version:

$ umlclass -M PPI -o samples/ppi_big.png -p "^PPI::"

(See http://perlcabal.org/agent/images/ppi_big.png.)

Draw FAST.pm from UML::Class::Simple's Test Suite

$ umlclass.pl -M FAST -o samples/fast.png -s 5x10 -r t/FAST/lib

This is an example of drawing classes contained in Perl source files.

BTW, PPI is a prerequisite of this module.

Draw Modules of Your Own

Suppose that you're a CPAN author too and want to produce a class diagram for all the classes contained in your lib/ directory. The following command can do all the hard work for you:

$ umlclass.pl -o mylib.png -r lib

or just plot the packages in the specified .pm files:

$ umlclass.pl -o a.png lib/foo.pm lib/bar/baz.pm

or even specify a pattern (in perl regex) to filter out the packages you want to plot:

$ umlclass.pl -o a.png -p "^Foo::" lib/foo.pm

Quite handy, isn't it? ;-)

OPTIONS

-c color

Sets the node color. Defaults to #f1e1f4.

You can either specify RGB values like #rrggbb in hex form, or color names like "grey" and "red".

-h

Shows the help message.

-M module

Preloads the module which contains the classes you want to depict. For example,

$ umlclass.pl -M PPI -o ppi.png -p "^PPI::"
-o outfile

Specifies the output file name. Note that the file extension will be honored. If you specify "-o foo.png", a PNG image named foo.png will be generated, and if you specify "-o foo.dot", the dot source file named foo.dot will be obtained. Likewise, "-o foo.yml" will lead to a YAML file holding the whole internal DOM data.

A typical usage is as follows:

$ umlclass.pl -o foo.yml lib/Foo.pm

# ...edit the foo.yml so as to adjust the class info
# feed the updated foo.dot back
$ umlclass.pl -o foo.dot foo.yml

# ...edit the foo.dot so as to adjust the graphviz dot source
# now feed the updated foo.dot back
$ umlclass.pl -o foo.png foo.dot

You see, umlclass.pl allows you to control the behaviors at several different levels. I really like this freedom, since tools can't always do exactly what I want.

-p regex

Specifies the pattern (perl regex) used to filter out the class names to be drawn.

-P

Shows public methods only.

-r

Processes subdirectories of input directories recursively.

-s <w>x<h>

Specifies the width and height of the resulting image. For example:

-s 3.6x7

where the unit is inches instead of pixels.

TODO

  • Add the -R class option which specifies the root class from which only its descendents will be shown.

AUTHOR

Agent Zhang <agentzh@gmail.com>

COPYRIGHT

Copyright 2006 by Agent Zhang. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as perl itself.

SEE ALSO

UML::Class::Simple.