Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8093995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:39:07+00:00 2026-06-05T20:39:07+00:00

Apologies, It looks like my original question was not able to correctly explain what

  • 0

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??)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:39:09+00:00Added an answer on June 5, 2026 at 8:39 pm

    If the subs are really very similar, why not generalize into ONE sub?

    my %validRequests = map {($_ => 1)} qq(UserDeleteRequest);
    
    sub SendRequest {
        my ($self, $request, $inputParam) = @_;
        my $config = $self->getConfig();
        return undef unless $validReqiests{$request}; # If want to verify
        # 
        $inputParam = getInputParamDefault($request) unless $inputParam; 
        return $self->_doRequest (REQUEST => $inputParam,
                                  PARAM => $inputParam));
    }
    

    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):

    # Code not tested.
    my %requestSubNames = ("UserDeleteRequest" => "UserDeleteRequest");
    foreach my $requestType (sort keys %requestSubNames) {
        no strict 'refs';
        my $subName = __PACKAGE__ . "::$requestSubNames{$requestType}";
        *{$subname} = sub { return $_[0]->SendRequest($requestType, $_[1]); };
            # Note - this may need to be closure-tweaked, it's 5am and I'm a bit asleep
        # Add to EXPORT/EXPORT_OK if needed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a really easy question, so apologies for not being more challenging!
The question says it all, really. I know a (Scala) Monad looks like this:
Apologies for creating a new thread. I was not able to frame the question
I apologize if this code looks a bit like a mess (considering the length);
Apologies if this doesn't make sense, i'm not much of an experienced programmer. Consider
Apologies if this is too ignorant a question or has been asked before. A
Apologies if this question is a bit obscure, I've been banging my head against
Apologies if this is a repost, I could not find the search terms to
I'm a newb to Python so apologies in advance if my question looks trivial.
I have a model called Action. It looks like this: class Action < ActiveRecord::Base

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.