[cgiapp] C::A::P::Routes

Mike Tonks fluffymike at googlemail.com
Thu Mar 4 04:33:25 EST 2010


I am using CAP::Routes and it works very well for me.

First off, I am using ScriptAlias to map the url and hide the script
name it the url:

So I have a few lines in my /etc/apache2/sites-available/app virtual host file:

        ScriptAlias /contacts   /var/www/app/cgi-bin/contacts.cgi
        ScriptAlias /jobs        /var/www/app/cgi-bin/jobs.cgi
        ScriptAlias /titles       /var/www/app/cgi-bin/titles.cgi


Then in contacts.cgi:

#!/usr/bin/perl -w

use strict;

use App::Contacts;

my $app = App::Contacts->new();

$app->run();

and finally the run modes in Contacts.pm


sub setup
{
	my $self = shift;

 	$self->start_mode('view');

	$self->routes_root('');

	$self->routes([
		'' 									=> 'view' ,
		'/guest'  								=> 'guest',
		'/staff/edit/:id'						=> 'edit_staff',
		'/staff/process/:id'					=> 'edit_staff_process',
		'/:id/address/new' 						=> 'edit_address',
		'/:id/address/:id2' 					=> 'edit_address',
		'/:id/address/process/:id2' 			=> 'edit_address_process',
		'/:id/email/process/:id2'				=> 'edit_email_process',
		'/:id/email/new' 						=> 'edit_email',
		'/:id/email/:id2' 						=> 'edit_email',
		'/:id' 									=> 'view' ,
		]);

etc.

Then my urls are e.g.

http://mysite/contacts - default page
http://mysite/contacts/1234 - view a specific contact record
http://mysite/contacts/1234/address/new - add address to a contact record

Note that I haven't got the /contacts/ bit in my routes_root - it
doesn't seem to need it.

I've been using this for 6 months plus now and as I say it works really well.

Hope this helps.

mike


More information about the cgiapp mailing list