CGI-Alternatives

 view release on metacpan or  search on metacpan

lib/CGI/Alternatives.pm  view on Meta::CPAN


        $cgi->render(html => qq{
            <html>
            <body>
                <form method="post">
                    <input name="user_input" type="text" />
                    <input type="submit" />
                </form>
                } . ($input ? "<p>You wrote: $input</p>" : '') . q{
            </body>
            </html>
        });
    };

For more information: L<https://blogs.perl.org/users/grinnz/2025/02/cgitiny---perl-cgi-but-modern.html>

=head1 MODERN DEPLOYMENT PRACTICES

=head2 PSGI Servers

All modern Perl web frameworks support PSGI. Here are the recommended PSGI
servers for production:

=over 4

=item * L<Starman> - High-performance preforking PSGI server (recommended for most uses)

=item * L<Gazelle> - Preforking Plack handler for performance freaks

=item * L<Twiggy> - AnyEvent-based PSGI server for real-time applications

=back

Example production deployment with Starman:

    plackup -s Starman \
        --workers=10 \
        --port=5000 \
        --daemonize \
        --pid=/var/run/myapp.pid \
        bin/app.psgi

=head2 Reverse Proxy

In production, run your PSGI app behind a reverse proxy like nginx or Apache:

nginx example:

    upstream myapp {
        server 127.0.0.1:5000;
    }

    server {
        listen 80;
        server_name myapp.example.com;

        location / {
            proxy_pass http://myapp;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

=head1 Dependency Management

This is a whole other topic, but given CGI.pm is no longer in the perl core
you would have to install it anyway. It would be a good idea to do this the
right way from beginning. I'm not going to cover this in detail here, there are
many many good sources of information on the web. Here are some links to get
you started:

=head2 Managing Perl Versions

=over 4

=item * L<https://github.com/tokuhirom/plenv> - plenv: Perl binary manager

=item * L<https://perlbrew.pl/> - perlbrew: Manage multiple perl installations

=back

=head2 Managing Perl Modules

=over 4

=item * L<https://metacpan.org/release/App-cpanminus> - cpanm: Fast, lightweight CPAN client

=item * L<https://metacpan.org/release/App-cpm> - cpm: Fast, parallel CPAN module installer (3x faster than cpanm)

=item * L<https://metacpan.org/release/Carton> - Carton: Perl module dependency manager (like bundler for Ruby)

=item * L<https://metacpan.org/release/local-lib> - local::lib: Use a local lib/ directory for modules

=back

Modern approach using cpanfile and cpm:

Create a cpanfile:

    requires 'Dancer2', '0.400000';
    requires 'Template', '2.26';
    requires 'Starman', '0.4015';

Install dependencies:

    # Fast parallel installation
    cpm install

    # Or with cpanm
    cpanm --installdeps .

Lock dependencies with Carton:

    carton install
    carton exec plackup bin/app.psgi

=head1 TESTING

One major advantage of modern frameworks is testability. All the frameworks
mentioned support easy testing:



( run in 2.220 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )