Class::Sniff: combine separate inheritance graphs.

Ovid on 2009-02-15T15:04:50

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';


    
        
        This is a title
        ";
        ?>
    
    
        

Do not edit this HTML lest the tests fail!!!



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.


With Methods

kzys on 2009-02-22T14:59:40

I'm using Class::Sniff to draw inheritance tree with methods. Thank you!

http://blog.8-p.info/2009/02/class-sniff-combine_graphs

Re:With Methods

Ovid on 2009-02-22T16:21:32

Sweet! I should play around with that and see if there's a clean way for me to support that directly.