Ray,

I second this method recommended by Hans.  I strongly recommend staying away
from putting use statements in all of your components if you run Mason under
mod_perl.  This can lead to intermittent bugs due to race conditions if you
forget to put a use statement in a component where the code uses a module.

For example you write component a including a "use CGI" statement and
instanciates a CGI object.  Later you work on component b and instanciate a
CGI object.  When you test component B it works fine in development because
you've already tested component A which loaded CGI into the embedded perl
runtime.  However, when you push code to production or restart the server
you may find that sometimes component B doesn't work.  This happens because
you forgot to include a use CGI statement in component B.

Using all of your modules in your mason handler will ensure that you never
have to deal with such a race condition.

I've never used the PerlModule directive before but the mod_perl 2.0
documentation says that it's the equivalent of doing a "require MyModule"
which isn't exactly the same as a use statement.  perldoc -f use for
details.

-- Ben

On Wed, Nov 26, 2008 at 10:07 AM, Hans Dieter Pearcey <
[EMAIL PROTECTED]> wrote:

> On Wed, Nov 26, 2008 at 05:37:42PM +0900, Raymond Wan wrote:
> > Do I have to do a:
> >
> > "use MyModule;"
> >
> > in every file?  Is there a better alternative?  I don't mind putting a
> > PerlModule directive in my httpd.conf or a "use MyModule" in the
> > handler, but I am not sure if that achieves what I would like and is the
> > "correct way to do things".
>
> Code in your components is run in the HTML::Mason::Commands package.
>
> So, in your handler, you could do:
>
>  {
>    package HTML::Mason::Commands;
>    use MyModule; # imports a bunch of stuff
>    use Other::Module qw(some functions here);
>    # etc.
>  }
>
> hdp.
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Mason-users mailing list
> Mason-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mason-users
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to