DBIx::Class::TopoSort - The addition of topological sorting to DBIx::Class
Within your schema class:
__PACKAGE__->load_components('TopoSort');
Later:
my $schema = Your::App::Schema->connect(...); my @toposorted_sourcenames = $schema->toposort();
If you have a cycle in your relationships
my @toposorted_sourcenames = $schema->toposort( skip => { Artist => [qw/ first_album /], }, );
This adds a method to DBIx::Class::Schema which returns the full list of sources (similar to "sources" in DBIx::Class::Schema) in topological-sorted order.
A topological sort of the tables returns the list of tables such that any table with a foreign key relationship appears after any table it has a foreign key relationship to.
This class is not instantiable nor does it provide any methods of its own. All methods are added to the DBIx::Class::Schema class and are callable on objects instantiated of that class.
This is sugar for:
$self->toposort_graph(@_)->toposort();
Calling this method multiple times may return the list of source names in different order. Each order will conform to the gurantee described in the section on TOPOLOGICAL SORT.
This method will throw an error if there are any cycles in your tables. You will need to specify the skip parameter (described below) to break those cycles.
This returns a Graph object with a vertex for every source and an edge for every foreign key relationship.
It takes the following parameters.
This describes the list of relationships that should be ignored by the toposort algorithm. This is generally used if you have cycles in your schema (though it could possibly be useful in other ways, I guess). The value is a hashref. The keys of this hashref are source names and the values are arrays of relationship names.
skip => { Artist => [ qw/ first_album / ], },
"toposort" in Graph
Copyright (c) 2013 Rob Kinyon. All Rights Reserved. This is free software, you may use it and distribute it under the same terms as Perl itself.
To install DBIx::Class::TopoSort, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::TopoSort
CPAN shell
perl -MCPAN -e shell install DBIx::Class::TopoSort
For more information on module installation, please visit the detailed CPAN module installation guide.