in reply to Alternative to CGI.pm

I like to use PSGI/Plack. It's simple enough to learn and to use, but most people don't use Plack from scratch anymore unless they are making a web framework or prefer their own way to do it. They usually go for higher level and 'out-of-the-box' options, like Dancer2 web framework in case they want to save time and cost. There's also Mojolicious (which has Mojolicious::Lite that is great for microservice web applications prototyping) that you need to try.

Do you know how raccoons can be so slick at surviving?

Replies are listed 'Best First'.
Re^2: Alternative to CGI.pm
by RonW (Parson) on Mar 27, 2017 at 20:15 UTC

    Out of curiosity, I looked at the PSGI/Plack website and made an amusing discovery.

    Many years ago, before I "discovered" Perl, I wrote a webserver in AWK. It wasn't purely in AWK; I wrote a C program to listen for and accept incoming HTTP connections. It then read the request and "parsed" it into an array of name/value pairs, then exec'd AWK, using the array as the environment pointer.

    Seems I "invented" "ASGI". Not the same as PSGI, but very close.

      That sounds amazing! Any chance the codebase still lurking around somewhere?

      Do you know how raccoons can be so slick at surviving?

        Maybe. The USB "stick" that had the back up copy is long lost, though the PC it ran is still gathering dust. Hasn't been powered for over 10 years, so I have no idea if the hard disk or any of it will function any more.

        The C program was a basic TCP server with a while loop to accept a connection, fork, read the HTTP header line-by-line, slurp the content (Perl equiv: sysread($connection, $buffer, $contentlength)), use strchr(buffer, '\r') to break the content (which was assumed to be "application/x-www-form-urlencoded") into "key=value" pairs and build an array of pointers (the HTTP headers were also included in the array). Then it would execle(awkint, awkint, awkscript, NULL, array).

        The AWK script would then access the HTTP and form fields as environment variables, doing url-decode as needed, process the request and generate the response, including the HTTP headers, streaming it out STDOUT.

        This wasn't hard, just very tedious. My co-workers dubbed me "The Wizard of AWK".

        Then I "discovered" Perl.

Re^2: Alternative to CGI.pm
by Anonymous Monk on Mar 24, 2017 at 16:27 UTC
    Here is an example of using Plack to capture form queries:
    use Data::Dumper; use Plack::Request; use Plack::Response; my $app = sub { my $req = Plack::Request->new(shift); my $query = $req->parameters; my $res = Plack::Response->new(200); $res->body('<pre>' . Dumper($query) . '</pre>'); $res->finalize; };