This is in reference to a mod_perl/mason issue I've been running into, but I think I can phrase it outside those environments.....

Is there anyway to get Exporter to overwrite subroutines that have already been defined? i.e. I would like the output of test.pl below to be "module subroutine" but can't get that behavior w/o the commented out line.

---- test.pl ----

#!/usr/bin/perl use My::Module qw(testsub); ### works, but seems to defeat the purpose of Exporter # *testsub = \&My::Module::testsub; print testsub(), "\n"; sub testsub { # "local" definition of subroutine return "local subroutine"; }

---- My/Module.pm ----

package My::Module; BEGIN { use Exporter (); @ISA = qw(Exporter); @EXPORT_OK = qw(testsub); } sub testsub { # new definition for subroutine return "module subroutine"; } 1;
I've looked at the specific mod_perl related modules (Apache::StatINC, Apache::Reload, Stonehenge::Reload) but none of them seem to address this. They all seem to work fine if you use the full package (i.e. print My::Module::testsub(); works fine above) but I can't get main::testsub to see the new code w/o explicitly forcing it. Any ideas?

-Blake


In reply to 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.