NAME

DBIx::Class::Graph

VERSION

version 1.05

SYNOPSIS

package MySchema::Graph;

use base 'DBIx::Class';

__PACKAGE__->load_components("Graph", "Core");
__PACKAGE__->table("tree");
__PACKAGE__->add_columns("id", "name", "parent_id");

__PACKAGE__->connect_graph(predecessor => "parent_id");

my @children = $rs->get_vertex($id)->successors;

my @vertices = $rs->vertices;

# do other cool stuff like calculating distances etc.

DESCRIPTION

This module allows to create and interact with a directed graph. It will take care of storing the information in a relational database. It uses Graph for calculations. This module extends the DBIx::Class::ResultSet. Some methods are added to the resultset, some to the row objects.

NAME

DBIx::Class::Graph - Represent a graph in a relational database using DBIC

CONFIGURATION

load_components

__PACKAGE__->load_components(qw(Graph Core));

To use this module it has to loaded via load_components in the result class.

resultset_class

XXX

connect_graph(@opt)

__PACKAGE__->connect_graph( predecessor => 'parent_id' );
__PACKAGE__->connect_graph( successor   => 'child_id' );
__PACKAGE__->connect_graph( predecessor => { parents => 'parent_id' } );
__PACKAGE__->connect_graph( successor   => { childs => 'child_id' } );

The first argument defines how the tree is build. You can either specify predecessor or successor.

The name of the relation to the next vertex is defined by the second argument.

METHODS

ResultSet methods

get_vertex($id)

finds a vertex by searching the underlying resultset for $id in the primary key column (only single primary keys are supported). It's not as smart as the original "find" in DBIx::Class::ResultSet because it looks on the primary key(s) for $id only.

Result methods

The following methods are imported from Graph:

delete_vertex connected_component_by_vertex biconnected_component_by_vertex
weakly_connected_component_by_vertex strongly_connected_component_by_vertex
is_sink_vertex is_source_vertex is_successorless_vertex is_successorful_vertex
is_predecessorless_vertex is_predecessorful_vertex is_isolated_vertex is_interior
is_exterior is_self_loop_vertex successors neighbours predecessors degree
in_degree out_degree edges_at edges_from edges_to get_vertex_count random_successor
random_predecessor vertices_at

FAQ

How do I sort the nodes?

Simply sort the resultset

$rs->search(undef, {order_by => "title ASC"})->graph;

CAVEATS

Multigraph

Multipgraphs are not supported. This means you there can only be one edge per vertex pair and direction.

Speed

you should consider caching the Graph object if you are working with large number of vertices.

SEE ALSO

DBIx::Class::Tree, DBIx::Class::NestedSet

BUGS

See "CAVEATS"

AUTHOR

Moritz Onken, <onken@houseofdesign.de>

I am also avaiable on the DBIx::Class mailinglist

COPYRIGHT AND LICENSE

Copyright (C) 2008 by Moritz Onken

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

AUTHOR

Moritz Onken <onken@netcubed.de>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2011 by Moritz Onken.

This is free software, licensed under:

The (three-clause) BSD License