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 8886509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:34:33+00:00 2026-06-14T21:34:33+00:00

I am using the module Sub::Override to mock a subroutine during testing. I am

  • 0

I am using the module Sub::Override to mock a subroutine during testing. I am actually testing a subroutine named sub_a. sub_a is calling another subroutine sub_b to do some work. sub_b is actually executing some commands over the ssh connection which I want to mock in my testing mode. So I am using sub::override to mock sub_b.

sub_a{
 ...
 sub_b(arg1, arg2)
}

In my test code I am overriding it like this

my $override_sshCommand = override_sub( 'package::filename::sub_b', sub ($$) { return "success"; }, undef );

In the above code if sub_b and sub_a are in the same class then the override is successful. Otherwise the override does not work.
I can fix this issue by using the fully qualified name of sub_b when calling from sub_a

sub_a{
 ...
 package::filename::sub_b(arg1, arg2);
}

The above code fixes the issue and the override is successful. But I don’t want to do it like this, as I don’t own that code and also it looks ugly. Is there any other solution ?

  • 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-14T21:34:34+00:00Added an answer on June 14, 2026 at 9:34 pm

    I presume sub_b is imported by the package that contains sub_a?

    You’re changing the sub to which the name package_of_sub_b::sub_b refers.

    You’re not changing the sub to which the name package_of_sub_a::sub_b refers.

    If the second name you’re resolving, so you need to override the sub_b in the package that contains sub_a.

    override_sub( 'package_of_sub_a::sub_b', ... );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the module simplenews and during the registration process it reads Select the
We are using multi-module projects for the components of our software. The sub-modules spread
I'm using the Paramiko module to log into a server (ssh on some and
I am using the following module to reveal a sub menu: icisSite.fatNav = function(trigger){
I've some annotation-based controller inside a sub module. These modules are deployed as jar
Here is some bad code: Module test Sub Main() Console.WriteLine(1<2 = + cstr((1<2))) Console.WriteLine(2<1
Have some Perl code which is using the DBI module - (the code is
Using Python module re, how to get the equivalent of the \w (which matches
when using the module pattern in js i've notice that the main benefits are
I am using booking module in my Magento store. All works fine before a

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.