Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: CGI::Application with 'main' runmodes and 'sub' runmodes by Herkum
in thread CGI::Application with 'main' runmodes and 'sub' runmodes by wfsp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-05-22 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?