in reply to Improved CGI Design
I agree that this makes the hash bigger; but it should not be much of a resource drain since the extra values are references; and I find the regular structure of the hash makes it easier to see what goes on.sub get_branch_function { my $query = shift; # get all three levels of keys into variables, # setting defaults as necessary: my $action = $query->param('action') ? $query->param('action') : +'default'; my $confirm = $query->param('confirm') ? 'confirm' : 'default'; my $commit = $query->param('commit') ? 'commit' : 'default'; # set up the hash so that whatever combination of keys # it gets, it will produce a value: my %dispatch = ( add => { confirm => { commit => \&commit_dialog, default => \&add_dialog, }, default => { commit => \&add_dialog, default => \&add_dialog, }, }, remove => { confirm => { commit => \&commit_dialog, default => \&confirm_dialog, }, default => { commit => \&choose_dialog, default => \&choose_dialog, }, }, modify => { confirm => { commit => \&commit_dialog, default => \&confirm_dialog, }, default => { commit => \&choose_dialog, default => \&choose_dialog, }, }, default => { confirm => { commit => \&action_dialog, default => \&action_dialog, }, default => { commit => \&action_dialog, default => \&action_dialog, }, }, ); # now one step should return the right subroutine: return $dispatch{ $action }{ $confirm }{ $default }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Improved CGI Design
by Dogma (Pilgrim) on Apr 09, 2002 at 21:30 UTC | |
by George_Sherston (Vicar) on Apr 10, 2002 at 11:33 UTC |