Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Adding to legacy application: does it make sense to use PSGI in CGI mode

by hotpelmen (Scribe)
on Mar 02, 2021 at 03:07 UTC ( #11128982=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks,

There's a 20 yr old Perl/CGI web application that currently runs on Apache 2.4 and uses Perl 5.16. Linux box it runs on has one IP address and has no associated domain name.

It is still being actively used inside my company by a dozen of employees, and I was asked to add a new page to it (standard interaction with database and displaying of results in the browser). I may have to add a page or two again within a year or two, so looking ahead I want to use something better and newer than 'use CGI' and print.

Looks like in my situation I can't just add Dancer2-based scripts to legacy application as Dancer's routing seems to require a separate VirtualHost that I can't create in this no-domain single-IP situation. So I am thinking to use middle path: Template for HTML part of it, and I was advised to use PSGI in CGI mode for interacting with Apache instead of using CGI.pm.

Using PSFI in CGI mode looks easy to do, but I am new to it and I am trying to avoid any path that may make me regretful later. Based on your experience and wisdom, what will be the immediate benefits of using PSGI/Plack for the new page, and is there anything I should beware of? Other thoghts?

Thank you!

  • Comment on Adding to legacy application: does it make sense to use PSGI in CGI mode

Replies are listed 'Best First'.
Re: Adding to legacy application: does it make sense to use PSGI in CGI mode
by hippo (Chancellor) on Mar 02, 2021 at 09:12 UTC
    So I am thinking to use middle path: Template for HTML part of it,

    That sounds like a sensible compromise. With the templates stored in external files this would make any later move to some other architecture less problematic too.

    and I was advised to use PSGI in CGI mode for interacting with Apache instead of using CGI.pm.

    You can do this but be warned that it increases the start-up time of the CGI scripts substantially. In my own tests of this the run time of a trivial script increased by a factor of 5 or 6. If that's OK in your scenario then it might be worth doing, again with one eye on the future.


    🦛

Re: Adding to legacy application: does it make sense to use PSGI in CGI mode
by marto (Cardinal) on Mar 02, 2021 at 09:29 UTC

    "I may have to add a page or two again within a year or two, so looking ahead I want to use something better and newer than 'use CGI' and print."

    It sounds like this old app is still doing what you need for now, perhaps the easiest way forward would just be to copy an existing script as a starting point. Using templates is wise, however if you are looking for something long term see CGI::Alternatives. Personally I recommend Mojolicious for making web work fun and easy to get right.

Re: Adding to legacy application: does it make sense to use PSGI in CGI mode
by karlgoethebier (Abbot) on Mar 02, 2021 at 12:35 UTC

    See also as well as the nodes linked ibidem for a total abuse of «The System». Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Re: Adding to legacy application: does it make sense to use PSGI in CGI mode
by hotpelmen (Scribe) on Mar 02, 2021 at 14:59 UTC
    Thanks everybody for your input!
Re: Adding to legacy application: does it make sense to use PSGI in CGI mode
by Anonymous Monk on Mar 02, 2021 at 04:15 UTC

    Hi,

    When you say "application" what is that? And how is that different from "script"?

    What does the code look like? How many files comprise that thing?

    Have you ever read CGI to mod_perl Porting. mod_perl Coding guidelines?

    No, Dancer doesn't demands a VirtualHost, where'd you get that idea?

    Drop in a /cgi-bin/gavotte.cgi and dance at the speed of cgi

      Hi, thanks for taking time to respond. Please pardon my lack of experience with Dancer and PSGI, I just started looking into them, and I am sure I misunderstand some of their advantages or requirements to implement.

      Here some more details in response to your questions.

      When you say "application" what is that? And how is that different from "script"?

      By "Perl/CGI web application" I mean a collection of Perl/CGI scripts that are united by sitting in the same cgi-bin directory, sharing some code, and serving common business goal. Different from a single script only in number of scripts.

      What does the code look like? How many files comprise that thing?

      In each script Perl code uses CGI.pm to get request parameters and prints HTML. mod_perl is not being used anywhere in this. There are probably 50 or so of these scripts implementing 50 or so of pages. I am looking for an efficient way to add 1 more page to that collection. Maybe a page or two in a few months.

      Have you ever read CGI to mod_perl Porting. mod_perl Coding guidelines?

      No, I have not read it, why, are you recommending to use mod_perl for new pages?

      No, Dancer doesn't demands a VirtualHost, where'd you get that idea? Drop in a /cgi-bin/gavotte.cgi and dance at the speed of cgi

      I got that idea about VirtualHost from "Running under Apache" section of Dancer2::Manual::Deployment doc. I had an impression that to take advantage of Dancer's features I'd need entire skeleton directory and for that I need VirtualHost so that I could direct traffic to dispatch.cgi. I have not read enough to really understand the whole effort but I got a feeling that trying to fit Dancer2 into an old application will be too much work. However if a new page will be better off when implemented in Dancer2 (as opposed to CGI.pm+Template or PSGI/Plack) then any thoughts supporting it would be appreciated.

      So given all that, does my question about use of Template and PSGI/Plack to add occasional pages to old application make more sense?
        Ok. How many of those scripts did you write? The best advice i have for you is read the tutorial i linked and grab a copy of Modern Perl 2011-2012 Edition. Pretend PSGI doesn't exist for now. Copy one .cgi and turn it into a new page.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11128982]
Approved by Corion
Front-paged by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2021-06-19 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (93 votes). Check out past polls.

    Notices?