On Thursday, Sep 11, 2003, at 12:17 US/Pacific, fliptop wrote: [..]
the way i do it is to assign an action to each form. each action has associated parameters. the form sends the action in an <input type="hidden"> tag.
oh yes, in this case the 'trigger' I use in say
<input type="hidden" name="callForm" value="doDaemon">
This way we do not have to have 'one cgi script' per action. My general strategy is to just pass along the HASH of the query string and leave them up to the subs to sort out which they need, which they use, yada-yada.
d:My traditional trick is of the form d: d: my $qs = make_hash_of_query_string($request); d: my $actions = {....}; # the hash of subs
oh, sorry, maybe if I broke that out
my $action = { doDaemon => \&doDameon, showDaemon => \&show_daemon, kickDaemon => \&doDameon, .... };
It would be more obvious that my idea is to KNOW that a given 'callForm' value returned from the browser is associated with a given method that would deal with the rest of the pack up some HTML and ship it back. The 'kickDaemon' variant in there is when I have already worked out that it would be a possible 'callForm' value that can be passed to this CGI, from some other piece of code, and that the difference between what kickDaemon() and doDaemon() do ultimately was so negligible that I just put a 'flag foo' into the later and consolidated code...
d: my $callForm = $qs->{'callForm'} || 'main_display'; # get the callForm[..]
d:parameter
d:
d: my $page = (defined($action->{'callForm'}) ? # is it defined
d: $action->{'callForm'}->($qs) :
d: main_display($qs);
d:
d:Which of course requires me to maintain the Hash of $actions
{ my %REQ_PARAMS = ( action1 => { # criteria for action 1 }, action2 => { # criteria for action 2 }, etc... );
[..]
That was what I was trying to mostly avoid. The idea of the 'should()' would take me along the line
my $page = ($obj->should($action->{'callForm'})) ? $obj->${$action->{'callForm'}}($qs) : $obj->call_form_error($qs);
hence the should look like
my $REQ_PARM = { doDaemon => 1, .... }; .... sub should { defined($REQ_PARAMS->{$_[0]}); } .... sub doDaemon { .... } sub kickDaemon { $me=shift; $me->doDaemon(@_); } # the synonym trick...
Which still gives me a HASH to manage, plus the actual Sub.
ciao drieux
---
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]