1 package DBIx::Class::NestedSets;
5 use base qw( DBIx::Class );
7 __PACKAGE__->mk_classdata( 'nested_left_column' );
8 __PACKAGE__->mk_classdata( 'nested_right_column' );
10 sub set_nested_columns {
11 my( $class, $left_column, $right_column ) = @_;
12 $class->nested_left_column( $left_column );
13 $class->nested_right_column( $right_column );
17 my( $parent, $child ) = @_;
19 # Preload these since we will be useing them more than once.
20 my $right_column = $parent->nested_right_column();
21 my $left_column = $parent->nested_left_column();
22 my $parent_right = $parent->get($right_column);
23 my $child_extent = $child->extent();
25 # Find all nodes to the right of the parent, including the parent.
26 my $rs = $parent->search( {
27 $right_column => { '>=', $parent_right }
30 # Shift all nodes to the right by the extent of the child.
33 $right_column => { '+', $child_extent }
37 # Pop the child in to the space that we opened up.
39 $left_column => $parent_right,
40 $right_column => ($parent_right + $child_extent) - 1,
47 $self->get( $class->nested_right_column() ) -
48 $self->get( $class->nested_left_column() )