Yes there is: Table-driven programming.
For example, have several different sub-components that each do all of the input processing and HTML generation for a single page, then build a big lookup table (hash) that stores each sub-component name, then have the appropriate sub-component called using some query string parameter you embed in each form. In this example, I use the "op" parameter to tell us what operation (page) we're going to execute, then go look it up in the table, and if it exists, we execute it:
my %sub_components = ( default_page => 'defaultpage.comp' full_text_search => 'fulltextsearch.comp', filename_search => 'filenamesearch.comp', view_alignment => 'viewalignment.comp', add_folder => 'addfolder.comp' ... ); if ($op) { if (exists $sub_components{$op}) { # execute the appropriate sub-component: eval { $m->comp($sub_components{$op}, %ARGS) }; if ($@) { # handle die() from the sub-component... } } else { # handle a request with "op" set to an invalid operation... } } ... <%args> $op => 'default_page' </%args>
Notice, you have to pass the query string arguments you received by hand to the sub-component you excute using %ARGS. (You have to do this *even* if the sub-components are all defined in the same file as the top-evel component.) Another option is caller_args(), but that's kind of hack-ish.
In reply to Re: Handling different requests for a web app in one centralized place.
by William G. Davis
in thread Handling different requests for a web app in one centralized place.
by geekgrrl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |