CGI-Alternatives
view release on metacpan or search on metacpan
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;
}
}
# 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:
## Managing Perl Versions
- [https://github.com/tokuhirom/plenv](https://github.com/tokuhirom/plenv) - plenv: Perl binary manager
- [https://perlbrew.pl/](https://perlbrew.pl/) - perlbrew: Manage multiple perl installations
## Managing Perl Modules
- [https://metacpan.org/release/App-cpanminus](https://metacpan.org/release/App-cpanminus) - cpanm: Fast, lightweight CPAN client
- [https://metacpan.org/release/App-cpm](https://metacpan.org/release/App-cpm) - cpm: Fast, parallel CPAN module installer (3x faster than cpanm)
- [https://metacpan.org/release/Carton](https://metacpan.org/release/Carton) - Carton: Perl module dependency manager (like bundler for Ruby)
- [https://metacpan.org/release/local-lib](https://metacpan.org/release/local-lib) - local::lib: Use a local lib/ directory for modules
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
# TESTING
One major advantage of modern frameworks is testability. All the frameworks
mentioned support easy testing:
use Test::More;
use Plack::Test;
use HTTP::Request::Common;
my $app = MyApp->to_app;
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->(GET "/example_form");
is $res->code, 200;
like $res->content, qr/Say something/;
};
done_testing;
# MIGRATION STRATEGIES
## Gradual Migration
You don't have to migrate everything at once:
- 1. Start by wrapping your CGI scripts with Mojolicious::Plugin::CGI
- 2. Add new features using the framework's native routing
- 3. Gradually port old scripts to framework controllers
- 4. Extract common code into libraries
## Quick Wins
Start with these easy improvements:
- Move to PSGI for deployment flexibility
- Separate HTML into templates
- Use a proper PSGI server instead of CGI
- Add proper logging with [Log::Log4perl](https://metacpan.org/pod/Log%3A%3ALog4perl) or [Log::Dispatch](https://metacpan.org/pod/Log%3A%3ADispatch)
- Write tests for your routes
# ADDITIONAL RESOURCES
- [Task::Kensho](https://metacpan.org/pod/Task%3A%3AKensho) - A Glimpse at an Enlightened Perl
- [https://perlmaven.com/](https://perlmaven.com/) - Perl Maven tutorials
- [https://www.perl.com/](https://www.perl.com/) - Perl.com articles
- [https://blogs.perl.org/](https://blogs.perl.org/) - Perl community blogs
# SEE ALSO
[Task::Kensho](https://metacpan.org/pod/Task%3A%3AKensho) - A Glimpse at an Enlightened Perl
[PSGI](https://metacpan.org/pod/PSGI) - Perl Web Server Gateway Interface Specification
[Plack](https://metacpan.org/pod/Plack) - PSGI toolkit and servers
# AUTHOR INFORMATION
Lee Johnson - `leejo@cpan.org` (LEEJO)
This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself. If you would like to contribute documentation
please raise an issue / pull request:
https://github.com/leejo/cgi-alternatives
( run in 0.863 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )