CGI scripts and modular design?

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default CGI scripts and modular design?

    Howdy,

    I've been poking through some different shopping cart software, trying
    to decide which one to use. All of them use piped filehandles or
    backticks to handle modularization.

    I will be modifying my store with some very custom requirements. It
    will be about a dozen modules before it is complete.

    My question is, Is there are reason why CGI scripts don't:

    use lib "./lib" ;

    and use modular code instead of backticking everything? My virtual
    hosting ISP permits calling locally installed libraries. Is it common
    practice for ISP's to not allow this? If I use modular design am I
    hurting my portability if I decide to go with another webhosting
    service?

    I have the hardest darned time sorting through the bazillion scripts
    in my cgi-bin. If I can't come up with a reason not to, I am turning
    half of them into object libraries, and sticking them in /cgi-bin/lib

    The only reason I can think of for not doing this is executable size.
    If memory is quota'd this could be a problem. The quota would have to
    be pretty anemic to be a factor though.

    Comments? Recomendations?

    Can other folks confirm that they do this too?

    -Thanks in advance
    -Matt
    psyshrike Guest

  2. Similar Questions and Discussions

    1. CS: Scripts do not appear in Scripts menu
      I have several utility AppleScripts that I created for Illustrator 10. I'd like to use these in CS, and they work correctly when I choose "Browse"...
    2. Modular Text into Projector
      This is probably something simple, but I can't seem to make it work. I want to be able to create a Shockwave project that will end up being a CD...
    3. Modular Photoshop?
      Maybe this topic should be in the request section, but I think here it will get more attention and probably this suggestion is too dumb as I don't...
    4. Modular design using ASP
      Mike, I don't follow this exactly. In your third paragraph, what is a concrete example of what you can do with PHP but not ASP? Paul "Mike"...
    5. Ideas for a modular config file?
      Hi folk, Right now I have a project that has a "bind-style" config file that is parsed with the aid of flex and bison. It looks a bit like this:...
  3. #2

    Default Re: CGI scripts and modular design?

    In article <79485f9d.0409280741.340cba6b@posting.google.com >,
    psyshrike <shrike@cyberspace.org> wrote:
    >Howdy,
    >
    >I've been poking through some different shopping cart software, trying
    >to decide which one to use. All of them use piped filehandles or
    >backticks to handle modularization.
    >
    >I will be modifying my store with some very custom requirements. It
    >will be about a dozen modules before it is complete.
    >
    >My question is, Is there are reason why CGI scripts don't:
    >
    >use lib "./lib" ;
    >
    >and use modular code instead of backticking everything? My virtual
    >hosting ISP permits calling locally installed libraries. Is it common
    >practice for ISP's to not allow this? If I use modular design am I
    >hurting my portability if I decide to go with another webhosting
    >service?
    Possibly, if their webserver is configured to execute scripts with an absolute
    path.
    >I have the hardest darned time sorting through the bazillion scripts
    >in my cgi-bin. If I can't come up with a reason not to, I am turning
    >half of them into object libraries, and sticking them in /cgi-bin/lib
    No, definitely do this.
    >Comments? Recomendations?
    Try at the top of your scripts -

    BEGIN {
    $location = $ENV{'SCRIPT_FILENAME'};
    $location =~ s!/[^/]+$!! || $location = '.';
    unshift(@INC,"${location}/lib");
    };

    That seems to cater nicely for such things - if you're called with an absolute
    path it'll push <path>/lib into the include list, if not it'll add './lib'.

    Also, because it does an unshift on @INC you'll get modules in your lib before
    ones in the main perl tree, which means you can "upgrade" stuff by copying your
    own version in, at least for pure perl modules.
    --
    Today's proposed addition to the PDP-11 instruction set:
    EPI Execute Programmer Immediately
    Today's fatal mistake:
    #include <pi-syspkt.h> [ My homepage is [url]http://www.trout.me.uk[/url] ]
    Matt S Trout Guest

  4. #3

    Default Re: CGI scripts and modular design?

    psyshrike wrote:
    > My question is, Is there are reason why CGI scripts don't:
    >
    > use lib "./lib" ;
    >
    > and use modular code instead of backticking everything?
    The authors learned Perl 10 years ago?

    What you say is of course not true for all CGI scripts. There is no
    reason for you to not apply Perl 5 style and incorporate code via modules.

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
    Gunnar Hjalmarsson Guest

  5. #4

    Default Re: CGI scripts and modular design?

    [email]shrike@cyberspace.org[/email] (psyshrike) wrote in
    news:79485f9d.0409280741.340cba6b@posting.google.c om:
    > Howdy,
    >
    > I've been poking through some different shopping cart software, trying
    > to decide which one to use. All of them use piped filehandles or
    > backticks to handle modularization.
    >
    > I will be modifying my store with some very custom requirements. It
    > will be about a dozen modules before it is complete.
    >
    > My question is, Is there are reason why CGI scripts don't:
    >
    > use lib "./lib" ;
    What is . ? I remember that there was (is?) no guarantee that it's the
    cwd of your script. You can use FindBin to solve this problem though.
    > and use modular code instead of backticking everything? My virtual
    > hosting ISP permits calling locally installed libraries. Is it common
    > practice for ISP's to not allow this?
    Some don't give shell access.
    > If I use modular design am I
    > hurting my portability if I decide to go with another webhosting
    > service?
    There is so much choice in webhosting those days that it's not that
    difficult to find one that meets your requirements.

    --
    John MexIT: [url]http://johnbokma.com/mexit/[/url]
    personal page: [url]http://johnbokma.com/[/url]
    Experienced programmer available: [url]http://castleamber.com/[/url]
    Happy Customers: [url]http://castleamber.com/testimonials.html[/url]
    John Bokma Guest

  6. #5

    Default Re: CGI scripts and modular design?

    [email]shrike@cyberspace.org[/email] (psyshrike) writes:

    [...]
    > I have the hardest darned time sorting through the bazillion scripts
    > in my cgi-bin. If I can't come up with a reason not to, I am turning
    > half of them into object libraries, and sticking them in /cgi-bin/lib
    Sticking them in cgi-bin/lib might make them directly executable,
    depending on Web server configuration, which may not be what you want
    (especially if including the file has side-effects).

    I usually create a cgi-lib directory outside of the Web server's root,
    and put all CGI libraries in there. That way they can't be read or
    executed directly by the Web server.

    I sometimes also set the PERL5LIB environment variable in Apache to
    specify where my libraries are, then use this code to untaint it and
    pull it in:

    BEGIN {
    if ($ENV{PERL5LIB} and $ENV{PERL5LIB} =~ /^(.*)$/)
    {
    # Blindly untaint. Taintchecking is to protect from Web data;
    # the environment is under our control.
    eval "use lib '$_';"
    foreach (reverse split(/:/,$1));
    }
    }

    That makes it easier to use the same script in different locations, by
    just changing the Apache config (with .htaccess if you don't control
    the entire server).

    Overall, this is a very good idea. It should make your code easier to
    maintain, encourage you to re-use code, and ensure that when you fix a
    bug in one place it is fixed everywhere.

    -----ScottG.
    Scott W Gifford Guest

  7. #6

    Default Re: CGI scripts and modular design?

    John Bokma wrote:
    >> My virtual hosting ISP permits calling locally installed
    >> libraries. Is it common practice for ISP's to not allow this?
    >
    > Some don't give shell access.
    Assuming we are talking about pure Perl modules, why would you need
    shell access to upload them to a local library?

    Possible providers who permit that you run your own CGI scripts
    written in Perl, but don't 'permit' the use of own modules, are
    ignorant and not worth to take into consideration.

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
    Gunnar Hjalmarsson Guest

  8. #7

    Default Re: CGI scripts and modular design?

    Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:2rttfiF1e66a7U1@uni-
    berlin.de:
    > John Bokma wrote:
    >>> My virtual hosting ISP permits calling locally installed
    >>> libraries. Is it common practice for ISP's to not allow this?
    >>
    >> Some don't give shell access.
    >
    > Assuming we are talking about pure Perl modules, why would you need
    > shell access to upload them to a local library?
    make? Unless you have exact the same environment as your hosting provider.
    There was a time I developed stuff on IRIX :-D
    > Possible providers who permit that you run your own CGI scripts
    > written in Perl, but don't 'permit' the use of own modules, are
    > ignorant and not worth to take into consideration.
    Sometimes you can get a "shell" via CGI :-D, but I prefer the real thing.

    --
    John MexIT: [url]http://johnbokma.com/mexit/[/url]
    personal page: [url]http://johnbokma.com/[/url]
    Experienced programmer available: [url]http://castleamber.com/[/url]
    Happy Customers: [url]http://castleamber.com/testimonials.html[/url]
    John Bokma Guest

  9. #8

    Default Re: CGI scripts and modular design?

    John Bokma wrote:
    > Gunnar Hjalmarsson wrote:
    >> John Bokma wrote:
    >>> Some don't give shell access.
    >>
    >> Assuming we are talking about pure Perl modules, why would you
    >> need shell access to upload them to a local library?
    >
    > make?
    Okay, but make isn't necessary. Simply uploading the .pm files to the
    right directories is sufficient. I did that successfully for several
    years as long as I had a hosting account without shell access.

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
    Gunnar Hjalmarsson Guest

  10. #9

    Default Re: CGI scripts and modular design?

    Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:2ru3msF1eom8pU1@uni-
    berlin.de:
    > John Bokma wrote:
    >> Gunnar Hjalmarsson wrote:
    >>> John Bokma wrote:
    >>>> Some don't give shell access.
    >>>
    >>> Assuming we are talking about pure Perl modules, why would you
    >>> need shell access to upload them to a local library?
    >>
    >> make?
    >
    > Okay, but make isn't necessary. Simply uploading the .pm files to the
    > right directories is sufficient. I did that successfully for several
    > years as long as I had a hosting account without shell access.
    If it's pure Perl, ok. But when you need a C compiler... And let's hope you
    can access that one. Otherwise you need access to the same OS, or worse
    depending on how you link.

    --
    John MexIT: [url]http://johnbokma.com/mexit/[/url]
    personal page: [url]http://johnbokma.com/[/url]
    Experienced programmer available: [url]http://castleamber.com/[/url]
    Happy Customers: [url]http://castleamber.com/testimonials.html[/url]
    John Bokma Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139