Graph::Reader::LoadClassHierarchy - load Graphs from class hierarchies


Graph-Reader-LoadClassHierarchy documentation Contained in the Graph-Reader-LoadClassHierarchy distribution.

Index


Code Index:

NAME

Top

Graph::Reader::LoadClassHierarchy - load Graphs from class hierarchies

SYNOPSIS

Top

  use Graph;
  use Graph::Reader::LoadClassHierarchy;

  my $reader = Graph::Reader::LoadClassHierarchy->new;
  my $graph  = $reader->read_graph('Foo::Bar');

DESCRIPTION

Top

Graph::Reader::LoadClassHierarchy is a class for loading a class hierarchy into a directed graph.

METHODS

Top

new

  my $reader = Graph::Reader::LoadClassHierarchy->new;

Constructor - generate a new reader instance. Doesn't take any arguments.

read_graph

  my $graph = $reader->read_graph( $class_name );

Builds a graph with the class hierarchy of $class_name.

AUTHOR

Top

Florian Ragwitz <rafl@debian.org>

BUGS

Top

Please report any bugs or feature requests to bug-graph-reader-loadclasshierarchy at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Graph-Reader-LoadClassHierarchy. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Graph::Reader::LoadClassHierarchy

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Graph-Reader-LoadClassHierarchy

* CPAN Ratings

http://cpanratings.perl.org/d/Graph-Reader-LoadClassHierarchy

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Graph-Reader-LoadClassHierarchy

* Search CPAN

http://search.cpan.org/dist/Graph-Reader-LoadClassHierarchy

COPYRIGHT & LICENSE

Top


Graph-Reader-LoadClassHierarchy documentation Contained in the Graph-Reader-LoadClassHierarchy distribution.
package Graph::Reader::LoadClassHierarchy;

use strict;
use warnings;
use Graph;

our $VERSION = '0.01';

sub new {
    my ($class) = @_;

    my $self = bless {}, $class;
    return $self;
}

sub read_graph {
    my ($self, $class_name) = @_;

    my $graph = Graph->new;

    $graph->add_vertex($class_name);
    $self->_read_graph($graph, $class_name);

    return $graph;
}

sub _read_graph {
    my ($self, $graph, $class_name) = @_;

    my @superclasses;
    {
        no strict 'refs';
        @superclasses = @{ $class_name . '::ISA' };
    }

    for my $superclass (@superclasses) {
        $graph->add_vertex($superclass);
        $graph->add_edge( $class_name => $superclass );

        $self->_read_graph($graph, $superclass);
    }
}

1; # End of Graph::Reader::LoadClassHierarchy