Hi, 
In one my classes i have this boilerplate code block that is repeated all
over ....

sub start {
    my ( $self,  $value ) = @_;
    $self->{'_start'} = $value if defined $value;

## -- from here
    $self->throw( "Only adjacent residues when location type "
          . "is IN-BETWEEN. Not ["
          . $self->{'_start'}
          . "] and ["
          . $self->{'_end'}
          . "]" )
      if defined $self->{'_start'}
      && defined $self->{'_end'}
      && $self->location_type eq 'IN-BETWEEN'
      && ( $self->{'_end'} - 1 != $self->{'_start'} );
    return $self->{'_start'};
## -- here

}

then again ....

sub end {
    my ( $self,  $value ) = @_;

    $self->{'_end'} = $value if defined $value;

    #assume end is the same as start if not defined
    if ( !defined $self->{'_end'} ) {
        if ( !defined $self->{'_start'} ) {
            $self->warn('Calling end without a defined start position');
            return;
        }
        $self->warn('Setting start equal to end');
        $self->{'_end'} = $self->{'_start'};
    }

## ----

    $self->throw( "Only adjacent residues when location type "
          . "is IN-BETWEEN. Not ["
          . $self->{'_start'}
          . "] and ["
          . $self->{'_end'}
          . "]" )
      if defined $self->{'_start'}
      && defined $self->{'_end'}
      && $self->location_type eq 'IN-BETWEEN'
      && ( $self->{'_end'} - 1 != $self->{'_start'} );

    return $self->{'_end'};
#---------
}


Is there any way moose can be used here for more code resuage. I thought
about converted it to a type but still couldn't figure out how that can
be done.


thanks, 
-siddhartha

Reply via email to