NAME

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

SYNOPSIS

package MySchema::Graph;

use strict;
use warnings;

use base 'DBIx::Class';

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

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

# predecessor can also be a relationship

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

# 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.

Important: This is a developer release! It works fine for simple layouts (see tests) but does not yet work if you use relationships to address the parents/childs. =head1 METHODS

connect_graph(@opt)

The first argument is the relation to the next vertex. Possible values: "predecessor" and "successor"

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

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.

ADDITIONAL GRAPH METHODS

Graph lacks some useful methods

all_successors($v)

Returns all successors of a vertex $v. It's a recusive method. It avoids infinite loops.

all_predecessors($v)

Returns all predecessors of a vertex $v. It's a recusive method. It avoids infinite loops.

FAQ

How do I sort the nodes?

Simply sort the resultset

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

CAVEATS

Integrity

It might be possible that some database actions are not recognized by the graph object and thus do not represent the correct status of the graph. To make sure you are working with the correct graph object reload it after editing the graph.

Multigraph

you should ommit creating multigraphs. Most graph algorithms expect a simple graph and may break if they get a multigraph.

Speed

you should consider caching the output of your scripts since retrieving and creating a Graph is not very fast.

SEE ALSO

Mention other useful documentation such as the documentation of related modules or operating system documentation (such as man pages in UNIX), or any relevant external documentation such as RFCs or standards.

I am also avaiable on the DBIx::Class mailinglist

TODO

  • Allow mulle oulle

  • und so weiter

BUGS

See "CAVEATS"

AUTHOR

Moritz Onken, <onken@houseofdesign.de>

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.