Revision history for DBIx::Class::Tree
0.01000
+ - Added is_leaf, is_root, and is_branch to AdjacencyList.
+ - Added a validation override for set_primary_key().
- Removed the _grouping_clause override method.
- Created a TODO document.
- attach_child() attach_sibling() now accept more than
- Support DAGs.
- - Add is_leaf, is_parent, is_branch, and is_root.
- Tree::Visitor
- Come up with a better name for attach_before and
attach_after.
=head1 COMPONENTS
-L<DBIx::Class::Tree::AdjacencyList> - Manage a tree of data using the common adjacency list model. (EXPERIMENTAL)
-
-L<DBIx::Class::Tree::AdjacencyList::Ordered> - Glue DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList together. (EXPERIMENTAL)
+L<DBIx::Class::Tree::AdjacencyList> - Manage a tree of data using the
+common adjacency list model. (EXPERIMENTAL)
+
+L<DBIx::Class::Tree::AdjacencyList::Ordered> - Glue DBIx::Class::Ordered
+and DBIx::Class::Tree::AdjacencyList together. (EXPERIMENTAL)
+
+=head1 DAG
+
+All tree related modules must conform to have and use the basic traversal
+methods of a DAG. For the most part this just means that Tree modules
+must provide the appearance of having multiple parents per node (via a
+parents() method) but may very well never return more than one parent.
+All utility modules, such as a Visitor module, should do its best to
+never assume that a node only has one parent. There are situations
+where this is not possible - in those cases the module's documentation
+should clearly state that it is not compatible with DAGs.
+
+So far there is no Tree::DAG module, but there will be. These requirements
+are vague, and the requirements of Tree modules to be DAG compatible will
+become more defined in due course.
=head1 AUTHOR
return $return;
}
+=head2 is_leaf
+
+ if ($obj->is_leaf()) { ... }
+
+Returns 1 if the object has no children, and 0 otherwise.
+
+=cut
+
+sub is_leaf {
+ my( $self ) = @_;
+ return $self->result_source->resultset->search(
+ { $self->_parent_column => $self->id() },
+ { limit => 1 }
+ )->count();
+}
+
+=head2 is_root
+
+ if ($obj->is_root()) { ... }
+
+Returns 1 if the object has no parent, and 0 otherwise.
+
+=cut
+
+sub is_root {
+ my( $self ) = @_;
+ return ( $self->get_column( $self->_parent_column ) ? 1 : 0 );
+}
+
+=head2 is_branch
+
+ if ($obj->is_branch()) { ... }
+
+Returns 1 if the object has a parent and has children.
+Returns 0 otherwise.
+
+=cut
+
+sub is_branch {
+ my( $self ) = @_;
+ return ( ($self->is_leaf() or $self->is_root()) ? 0 : 1 );
+}
+
+=head2 set_primary_key
+
+This method is an override of DBIx::Class' method for setting the
+class' primary key column(s). This method passes control right on
+to the normal method after first validating that only one column is
+being selected as a primary key. If more than one column is then
+an error will be thrown.
+
+=cut
+
+sub set_primary_ley {
+ my $self = shift;
+ if (@_>1) {
+ croak('You may only specify a single column as the primary key for adjacency tree classes');
+ }
+ return $self->next::method( @_ );
+}
+
1;
__END__