I once did something along that line, but eventually decided on a different architecture so I abandoned that work. You can find a basic implementation of something close to what you want at Versioned modules.

UPDATE
Oops, I misread the question. Your problem is not what you think it is. It is an order of action issue. Here is the order of actions with the section commented out:

  1. Start your script.
  2. Go off and load the module.
  3. import from the module.
  4. Compile the rest of the script, including overwriting the function.
  5. Execute the script, calling the function. (Get the local version.)
Here is the order of actions after uncommenting:
  1. Start your script.
  2. Go off and load the module.
  3. import from the module.
  4. Compile the rest of the script, including overwriting the function.
  5. Manually import the function again, overwriting the local function.
  6. Execute the script, calling the function. (Get the module version.)
As you see the issue isn't how you get the module to overwrite the local version, it is how you get the local version to not overwrite the module!

The answer is that you can't. But if you move the use to the *end* of the script you will get the module version. If you manually call import in your script you will likewise be able to get the module version. However you cannot prevent the code using the module from being able to overwrite what you exported. Which is really how it should be. Module authors should not be deliberately equipped with weapons to allow their bad assumptions to accidentally cause hard-to-fix grief for users of their code.


In reply to Re (tilly) 1: Redefining Exported Subroutines (esp. in mod_perl/mason) by tilly
in thread Redefining Exported Subroutines (esp. in mod_perl/mason) by blakem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.