Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: CGI::Application with 'main' runmodes and 'sub' runmodes

by Herkum (Parson)
on Apr 28, 2007 at 14:25 UTC ( #612553=note: print w/replies, xml ) Need Help??

in reply to CGI::Application with 'main' runmodes and 'sub' runmodes


  • If you use CGI::Application::Plugin::AutoRunmode you can get rid of the setup method.
  • I would keep the name of the instance scripts closely aligned with the Controller names.
  • You should also be using inheritance in your controllers for you to ensure consistency and reduce the amount of coding.

Example: instance script at /Sample/Launcher/Default.cgi

#!C:/Perl/bin/perl.exe use lib qw( /www/local/sw/admin/lib ); use Sample::Launcher; Sample::Launcher->new->run;

Now you know where every controller module is based upon the name of instance script. It provides consistency.

This would be your Main module.

package Sample::Main; use strict; use warnings; use base qw{CGI::Application}; use CGI::Application::Plugin::AutoRunmode; sub get_tmpl_path { my $self = shift; return '/Sample/'; } sub one :STARTRUNMODE { my $self = shift; my $tmpl = $self->load_tmpl( $self->get_tmpl_path() . 'One.tmpl' ); return $tmpl->output; } sub two :RUNMODE { my $self = shift; my $tmpl = $self->load_tmpl( $self->get_tmpl_path() . 'Two.tmpl' ); return $tmpl->output; } 1;

This sets you with some initial defaults. Now lets take advantage of this by inheriting its properties but and change the default path that is appropriate for that controller.

package Sample::Launcher; use strict; use warnings; use base 'Sample::Main'; sub get_tmpl_path { my $self = shift; return '/Sample/Launcher/'; }

Thats it! Your Sample::Launcher module has two run modes (One and Two), and can find the templates in '/Sample/Launcher/One.tmpl' and '/Sample/Launcher/Two.tmpl' . Notice, no redundancy! :)

Try that and see if it is not better for you.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://612553]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2022-05-21 06:27 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (76 votes). Check out past polls.