I've written a few applications which just display a template file, and the simplest way I found was to use the AUTOLOAD function.

That gets called for anything that hasn't got an explicit mapping setup. Inside that I will either show "Invalid node", or laod the existing template.

Code could look like this:

# # Called if the user submits an invalid run mode / node. # sub invalidnode { my ($self) = @_; # Get the node the user tried to use. my $q = $self->query(); my $node = $q->param("node"); if ( $node =~ /^([a-z]+)$/ ) { $node = $1; if ( -e "./templates/$node.tmpl" ) { my $html = $self->load_tmpl( "templates/$node.tmpl", global_vars => 1, ); return ( $html->output ); } } my $html = $self->load_tmpl( "templates/error.tmpl", global_vars => 1, ); return ( $html->output ); }

With at the setup:

$self->run_modes( 'home' => 'home', ..... 'AUTOLOAD' => 'invalidnode' );

As you see I merely test for the existance of a template - and if one exists it's loaded, if not I show an error page.

That means I can have ?node=FAQ, ?node=Contact, etc, which are just static templates and don't need any special handling.

Steve
---
steve.org.uk

In reply to Re: CGI::Application same function code by skx
in thread CGI::Application same function code by boboson

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.