In this model each row in a table has a prent ID column that references the
primary key of another row in the same table. Because of this the primary
key must only be one column and is usually some sort of integer. The row
-with a parent ID of 0 is the root row and is usually the parent of all
-other rows.
+with a parent ID of 0 is the root node and is usually the parent of all
+other rows. Although, there is no limitation in this module that would
+stop you from having multiple root nodes.
=head1 METHODS
$employee->parent( $parent_id );
Retrieves the object's parent object, or changes the object's
-parent to the specified parent or parent ID.
+parent to the specified parent or parent ID. If you would like
+to make the object the root node, just set the parent to 0.
+
+If you are setting the parent then 0 will be returned if the
+specified parent is already the object's parent and 1 on
+success.
=cut
=head2 attach_child
$parent->attach_child( $child );
+ $parent->attach_child( $child, $child, ... );
-Sets the child to the new parent.
+Sets the child, or children, to the new parent. Returns 1
+on success and returns 0 if the parent object already has
+the child.
=cut
sub attach_child {
- my( $self, $child ) = @_;
- return $child->parent( $self );
+ my $self = shift;
+ my $return = 1;
+ foreach my $child (@_) {
+ $child->parent( $self );
+ }
+ return $return;
}
=head2 siblings
=head2 attach_sibling
- $this->attach_sibling( $that );
+ $obj->attach_sibling( $sibling );
+ $obj->attach_sibling( $sibling, $sibling, ... );
-Sets the passed in object to have the same parent
-as the calling object.
+Sets the passed in object(s) to have the same parent
+as the calling object. Returns 1 on success and
+0 if the sibling already has the same parent.
=cut
sub attach_sibling {
- my( $self, $node ) = @_;
- return $node->parent( $self->parent() );
+ my $self = shift;
+ my $return = 1;
+ foreach my $node (@_) {
+ $return = 0 if (!$node->parent( $self->parent() ));
+ }
+ return $return;
}
1;