Rob Kinyon > DBIx-Class-TopoSort-0.050001 > DBIx::Class::TopoSort

Download:
DBIx-Class-TopoSort-0.050001.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.050001   Source   Latest Release: DBIx-Class-TopoSort-0.050002

NAME ^

DBIx::Class::TopoSort - The addition of topological sorting to DBIx::Class

SYNOPSIS ^

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 /],
      },
  );

Alternately:

  my @toposorted_sourcenames = DBIx::Class::TopoSort->toposort($schema);

DESCRIPTION ^

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.

TOPOLOGICAL SORT

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.

METHODS ^

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.

toposort

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.

toposort (Class method)

Alternately, if you do not wish to use TopoSort as a component, you can call it as a class method on this class. The toposort() method is smart enough to distinguish.

Note: toposort_graph() does not distinguish - it assumes it will be called with the $schema object passed in.

toposort_graph

This returns a Graph object with a vertex for every source and an edge for every foreign key relationship.

It takes the following parameters.

skip

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 / ],
  },

SEE ALSO ^

"toposort" in Graph

AUTHOR ^

LICENSE ^

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.

syntax highlighting: