Apologies, It looks like my original question was not able to correctly explain what I am doing and what I want to achieve. Here is an updated question.
This may be the easiest question, but I can’t find an answer anywhere.
I have a large Perl module (say ABC.pm) which keeps on growing day by day as we add new functions. Most of these functions (almost 90%) send requests and process responses. Here is some code for one such request.
sub UserDeleteRequest
{
my ($self, $inputParam) = @_;
my $config = $self->getConfig();
return $self->_doRequest (REQUEST => 'UserDeleteRequest',
PARAM => $inputParam));
}
Similar to this, other functions are written and it keeps on growing as we add new requests.
Having a large file is becoming difficult to maintain. So, I am looking for some best practices to make this easier. One idea that I thought of was to split this large module into multiple files (how??)
If the subs are really very similar, why not generalize into ONE sub?
If there are other logical differences between some types of subs, you can address them by either doing proper OO with inheritance, as Ilion’s answer notes; or you can do the simpler approach of having a per-request-type hashes of helper sub references in simpler cases.
I added a special
getInputParamDefault()call get to address your comment “Sometimes caller of the function does not provide $inputParam then we have to find the default one and pass it to _doRequest subroutine.”UPDATE: If you MUST keep the original sub names due to legacy code calling them that you can’t refactor, you can auto-generate them (either using AUTOLOAD or by adding to namespace by hand):