Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday February 15, 2009
10:04 AM

Class::Sniff: combine separate inheritance graphs.

[ #38481 ]

I've just uploaded Class::Sniff 0.07. It no longer has any concept of "tree" (and this made the internal code easier to understand) and you can pass an instance to the constructor -- a minor tweak, but still very useful.

My favorite feature, though, is combining graphs. The following code lets me generate a nice PNG of HTML::TokeParser::Simple's inheritance hierarchy. (Sigh. No images allowed here.)

#!/usr/bin/env perl

use strict;
use warnings;

use Class::Sniff;
use HTML::TokeParser::Simple;

my $html = <<'END_HTML';
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
    <head>
        <!-- This is a comment -->
        <title>This is a title</title>
        <?php
            print "<!-- this is generated by php -->";
        ?>
    </head>
    <body alink="#0000ff" BGCOLOR="#ffffff">
        <h1>Do not edit this HTML lest the tests fail!!!</h1>
    <hr class="foo" />
    <hr class="bar"/>
    </body>
</html>
END_HTML
my $parser = HTML::TokeParser::Simple->new( string => $html );
my %seen;
my @sniffs;
while ( my $token = $parser->get_token ) {
    no warnings 'numeric';
    next if $seen{ ref $token }++;
    push @sniffs => Class::Sniff->new( { class => $token } );
}
my $sniff = pop @sniffs;
my $graph = $sniff->combine_graphs(@sniffs);
my $graphviz = $graph->as_graphviz();
open my $DOT, '|dot -Tpng -o graph.png' or die("Cannot open pipe to dot: $!");
print $DOT $graphviz;

You could also include UNIVERSAL with the universal => 1 argument to the constructor and all objects will be attached on graphs since that's the ultimate base class for everything.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.