in reply to Re: CGI script organisation
in thread CGI script organisation

But if the module gets relocated (which it surely will when I release it) that'll mess everything up. Who knows where other users will install the stuff?

Replies are listed 'Best First'.
Re: Re: Re: CGI script organisation
by metadoktor (Hermit) on Jan 27, 2002 at 05:56 UTC
    Why not create a modules subdirectory below your app so that you can do this.
    use mod_dir::module1; use mod_dir::module2; module1->foo(); module2->foo2();

    metadoktor

    "The doktor is in."

      I advise against that.
      use mod_dir::module1;
      equates to
      BEGIN { require mod_dir::module1; import mod_dir::module1; }
      Notice the import? That will break if the actual namespace is called module1, and not mod_dir::module1. Depending on the module, this can have a huge impact.

      Makeshifts last the longest.

      That's good too. I can use a dummy .htaccess file to block users from inadvertanly entering that directory.
Re: Re: Re: CGI script organisation
by dws (Chancellor) on Jan 27, 2002 at 05:52 UTC
    But if the module gets relocated (which it surely will when I release it) that'll mess everything up.

    Then your install procedure will need to plug in a correct path.

      Yeah, this is one way to do it. I can let the configure script process example.pl.in to example.pl to replace the paths with their actual values. It's ugly, but it'll do. Thanks!
        Yes, ugly indeed - have the CGI read another file which contains the configuration instead. I usually require a config.cgi located in the same directory as the script and looks something like
        #!perl -w use constant (OPTION1 => 'value1'); use constant (OPTION2 => 'value2'); use constant (OPTION3 => 'value3'); 1;
        Note that care should be taken with the server configuration in that case, and the file should be executable. On a properly configured server, calling this file on the URL will then result in a 500 server error.

        Makeshifts last the longest.

        Another aproach is setting module search path using enviroment variable PERL5LIB. This way you don't need use lib qw(/some/where) in your code. Your users (or your installation script) should put SetEnv PERL5LIB /some/where in Apache config instead of it.

        See perlrun for information about enviroment variables used by perl.

        --
        Ilya Martynov (http://martynov.org/)

Re: Re: Re: CGI script organisation
by thraxil (Prior) on Jan 27, 2002 at 23:12 UTC