[cgiapp] Runmodes in separate modules

Victor Bruno vicdamone at gmail.com
Sun Sep 6 18:53:12 EDT 2009


>> sub display_dashboard : Path('dashboard/')

>That's catalyst style code. The way I achieve what you are talking about 
>is to require in the relevant module based on the runmode name. That way 
>if you are in Vanilla CGI you only load the modules you need for the 
>current process. During the setup phase I check what modules are in a 
>set folder and populate the runmode has based on that.

After more searching, it looks like C::A::Dispatch is going to fit my needs
best. It allows me to have my runmodes organized in separate logical modules
and link to them dynamically from the url.

Here is what I ended up with:
###########################################################################
myApp_Dispatch.pl:
    use lib 'lib';

    use CGI::Application::Dispatch;
    CGI::Application::Dispatch->dispatch(
        prefix => 'MyApp::Controller'
    );

lib/MyApp.pm:
    package MyApp.pm;
    use base 'Titanium';

    sub setup {
              my ($self) = @_;
              return;
    }
    1;

lib/MyApp/Controller/Admin/Dashboard.pm:
    package MyApp::Controller::Admin::Dashboard;

    use base 'MyApp';

   sub setup {
      my ($self) = @_;
      $self->run_modes( [qw/ display_dashboard /] );

   }

   sub display_dashboard {
      return qq{<html><body>Dashboard in a mod</body></html>};
   }
##########################################################################

Then my url can look like:
http://dev1/MyApp/myApp_Dispatch.pl/admin_dashboard/display_dashboard/



More information about the cgiapp mailing list