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 must be a column of this row
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.
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.
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. If you see such a behaviour please report it to me.
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.
TODO
- Add support for relationships as connector
-
This would allow graphs which have multiple parents and multiple children
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.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 117:
You forgot a '=back' before '=head1'