I second the vote for CGI::Prototype. I'd also suggest looking at CGI::Ex::App. It lets you choose if you want some run modes handled by other classes, or handled by locally.

#!/usr/bin/perl package Foo; use strict; use warnings; use base qw(CGI::Ex::App); Foo->new->navigate; exit; sub base_dir_abs { '/var/www/templates' } ### tell the application to ### look for a module to handle each run mode (step) sub allow_morph { 1 } { # This could be in its own file - or # embedded in here is fine # you can get here by going to # /cgi-bin/my_cgi # or /cgi-bin/my_cgi/main # or /cgi-bin/my_cgi?step=main package Foo::Main; sub file_print { return \ <<'HERE'; <h1>Step Main</h1> This is the default run mode. You said [% hello %]. HERE sub hash_swap { return {hello => "I'm main!"}; } } # end of Foo::Main # you get to step2 by calling # /cgi-bin/my_cgi?step=step2 # or # /cgi-bin/my_cgi/step2 # these methods are just sitting the the Foo class sub step2_file_print { return \ <<'HERE'; <h1>I'm in step 2</h1> You said [% hello %]. HERE sub step2_hash_swap { return {hello => 'Hello Step2'}; } # uncomment for a trace of which methods were looked for # sub post_navigate { # use CGI::Ex::Dump qw(debug); # debug shift->dump_history; #}


my @a=qw(random brilliant braindead); print $a[rand(@a)];

In reply to Re^2: CGI::Application with 'main' runmodes and 'sub' runmodes by Rhandom
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":



  • 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.