my $sibling = $employee->first_sibling();
-Returns the first sibling object.
+Returns the first sibling object, or 0 if the first sibling
+is this sibliing.
=cut
sub first_sibling {
my( $self ) = @_;
+ return 0 if ($self->get_column($self->position_column())==1);
return ($self->result_source->resultset->search(
{
$self->position_column => 1,
my $sibling = $employee->last_sibling();
-Return the last sibling.
+Return the last sibling, or 0 if the last sibling is this
+sibling.
=cut
sub last_sibling {
my( $self ) = @_;
my $count = $self->result_source->resultset->search({$self->_collection_clause()})->count();
+ return 0 if ($self->get_column($self->position_column())==$count);
return ($self->result_source->resultset->search(
{
$self->position_column => $count,
sub run_tests {
- plan tests => 56;
+ plan tests => 66;
my $schema = shift;
my $employees = $schema->resultset('Employee::Positioned');
if ($position==1) {
ok( !$employee->previous_sibling(), 'no previous sibling' );
ok( $employee->next_sibling(), 'next sibling' );
+ ok( !$employee->first_sibling(), 'no first sibling' );
+ ok( $employee->last_sibling(), 'last sibling' );
}
elsif ($position==$employees->count()) {
ok( $employee->previous_sibling(), 'previous sibling' );
ok( !$employee->next_sibling(), 'no next sibling' );
+ ok( $employee->first_sibling(), 'first sibling' );
+ ok( !$employee->last_sibling(), 'no last sibling' );
}
else {
ok( $employee->previous_sibling(), 'previous sibling' );
ok( $employee->next_sibling(), 'next sibling' );
+ ok( $employee->first_sibling(), 'first sibling' );
+ ok( $employee->last_sibling(), 'last sibling' );
}
}