Skip to content

Porting CGI Application

markstos edited this page Nov 27, 2010 · 3 revisions

Porting from old CGIs to Mojolicious

After you found Mojolicious you should think of porting your old cgi scripts to Mojolicious.

  • Why should you care for old stuff which is aged back to the earlies of the internet?

  • Why should you keep old source code in production which is untestable and unmaintainable?

Get yourself a life and remember the times when web development was actually fun. Porting web application to Mojolicious can be easy and fun.

Porting from CGI::App

CGI::Application is a lightweight CGI environment which uses a parameter (usually rm) to decide about the actions to take when a requests comes to the CGI. To switch CGI::App web applications to Mojolicious is an easy task. Just add a hook to Mojolicious which parses the request for the rm parameter and forwards the request to the appropiate route in Mojolicious. This method allows you to keep old webpages and scripts to stay in production for compatibility and to implement new webpages using the Mojolicious route based method.

Here is a sample code snippet how to add an hook. Just put this somewhere in your application before the start() command.

app->plugins->add_hook(before_dispatch => sub {
                my ($self, $c) = @_;
                return unless my $rm = $c->param('rm');
                $c->req->url->path($rm);
        }
);
Clone this wiki locally