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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:48:43+00:00 2026-05-23T09:48:43+00:00

An external Perl library that I am using has a dependency (DBD::mysql) that I

  • 0

An external Perl library that I am using has a dependency (DBD::mysql) that I will not be using in my application (DBD::SQLite), so I would like the system to just pretend the dependency is there, even if it’s a “fake”.

Can I just create an empty DBD::mysql.pm module that compiles or is there a more straightforward way of doing this?

  • 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-05-23T09:48:43+00:00Added an answer on May 23, 2026 at 9:48 am

    So I think there are few issues here.

    When you say dependency, do you mean the external module simply tries to require or use DBD::mysql? If that is the case then you should advise the developer that he shouldn’t be explicitly doing that because that defeats the purpose of using DBI. The database driver should be selected on the fly based on the DSN.

    Assuming that the author is merely useing the package name because he thought that was a useful or meaningful thing to do, then yes, you may override that package, and there are a few ways to do it.

    As you suggested, you can merely create your own module DBD/mysql.pm that would define the DBD::mysql package.

    There are some other things you could do if you are interested. Instead of littering your source tree with fake directories and files, you just need to convince Perl that the module was loaded. We can do this by directly manipulating %INC.

    package main;    # or whereever
    
    BEGIN {
        $INC{'DBD/mysql.pm'} = "nothing to see here";
    }
    

    Simply by adding this hash key, we preclude a search of the filesystem for the offending module. Observe that this is in a BEGIN block. If the external author did a use then we must populate this value before the use statement is evaluated. The use statements are equivalent to a require and import wrapped in a BEGIN.

    Now lets further speculate in the general sense that the external author was attempting to call methods of the package. You will get run time errors if there if those symbols don’t exist. You can take advantage of Perl’s AUTOLOAD to intercept such calls and do the right thing. What The right thing is can vary a lot, from simply logging a message to something more elaborate. For instance, you could use this facility to examine the depth of the coupling that the author introduced by monitoring all the calls.

    package DBD::mysql;
    
    sub AUTOLOAD {
        printf(
            "I don't wanna '%s' called from '%s'\n", $AUTOLOAD, caller(0)
          );
    }
    
    package main;    # or whereever
    
    BEGIN {
        $INC{'DBD/mysql.pm'} = "nothing to see here";
    }
    
    DBD::mysql::blah()
    

    Now let’s also cover the case where the offending author also created some object oriented instances of a class, and his code doesn’t properly account
    for your stub code. We will stub the constructor which we assume is new to just bless an anonymous hash with our package name. That way you won’t get
    errors when he calls methods on an instance.

    package DBD::mysql;
    
    sub AUTOLOAD {
        printf(
            "I don't wanna '%s' called from '%s'\n", $AUTOLOAD, caller(0)
        );
    }
    
    sub new {
        bless({}, __PACKAGE__)
    }
    
    package main;    # or whereever
    
    BEGIN {
        $INC{'DBD/mysql.pm'} = "nothing to see here";
    }
    
    my $thing = new DBD::mysql;
    
    $thing->blah()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that I would like to define in two different Perl
Perl has a lovely little utility called find2perl that will translate (quite faithfully) a
I'd like to unit test a Perl program of mine that is using backticks.
Perl supports three ways (that I know of) of running external programs: system :
For a Perl porting project I am using ActiveState's Komodo IDE 5.1 For external
I'm using backticks to run an external command in perl, but I've got a
I currently have a Perl script that runs an external command on the system,
Possible Duplicate: How can I remove external links from HTML using Perl? Alright, i'm
I have an external module, that is returning me some strings. I am not
I have a script that uses modules that are external to the standard Perl

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.