fREWdiculous!
14 Jan
So I haven’t totally figured everything out about CGI::Application::Dispatch, but I am learning a lot. First off, here are two things that I learned today.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | package ACD::Dispatch; use base 'CGI::Application::Dispatch'; use warnings; sub dispatch_args { return { prefix => 'ACD', debug => 0, table => [ '/' => { app => 'Welcome', rm => 'index' }, # The rm must be optional if you want # /controller to go to the startrunmode. ':app/:rm?/:foo?' => { }, ], args_to_new => { PARAMS => { cfg_file => '/path/to/config.pl', } }, }; } 1; |
Now, notice the :foo param. If you want to get access to that in your controller you use
1 | $self->param('foo') |
but if you had a regular parameter as well and wanted to get access to that, you’d use
1 | $self->query->param('bar') |
One Response for "CGI::Application::Dispatch, optional paramters and optional runmodes"
Glad to see posts about CGI::App – thanks fRew.
A couple other things you can do in your Dispatch subclass are to create named paths and a default in a user supplied path is not found. For instance:
In the table array:
‘login’ => {prefix=> ‘ACD’, app => ‘User’, rm=>’login’},
You can supply a key in the returned hash to provide that named path as a default:
default => ‘login’,
Leave a reply