Suggestions,
- 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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.