Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a bunch of mason scripts that call a subroutine called 'MySubroutine'. The subroutine is in a '.pm' file. It took me about two hours but I have finally realized that my 'bug' is really just Mason not reflecting the changes that I am making to this subroutine. Occasionally my changes will go into effect but I can't figure out how or when.

The Mason scripts use the subroutine like this:

use MySubroutine;

The subroutine file is called 'MySubroutine.pm' and the first few lines of the file look like this:

package MySubroutine; use Exporter(); use DBI; @ISA = qw(Exporter); @EXPORT = qw(MySubroutine); sub MySubroutine { ... } 1;

I am new to Mason and have never had a problem like this with my previous experience in perl. Any suggestions?

Replies are listed 'Best First'.
Re: Mason subroutine not relefecting changes
by Paladin (Vicar) on Mar 13, 2007 at 22:41 UTC
    IIRC, it's not Mason causing the problem, but mod_perl, which caches the Perl to make things run faster. In my limited experience with Mason/mod_perl, what I do in this kind of case is just restart Apache, which clears the cache. There may be a better way, but I know this one works.
      Thanks for your response. However, this subroutine is part of a shopping cart and will be called numerous times. I can't keep restarting/reloading Apache. Is there a better way?
        You only have to restart after updates of the code. If you can't do that you shouldn't deploy work in progress to a production server.

        Anyway, depending on your version of mod_perl; for mod_perl 1.X you can use Apache::StatInc which will reload modules if they've been changed (this can mess up stuff if you have cached data/dependencies, but for simple modules it should work).

        For mod_perl 2.X (and apparently also, 1.X) you can use Apache::Reload / Apache2::Reload , which does more or less the same.

        updated: fixed link to apache::reload

Re: Mason subroutine not relefecting changes
by fmerges (Chaplain) on Mar 13, 2007 at 23:36 UTC