Mark Stosberg wrote:
In 2001, I posted on this list a suggestion for improving mode_param:
http://www.mail-archive.com/cgiapp%40lists.vm.com/msg00001.html

Years ago, Jesse realized the value of passing the run mode through
"PATH_INFO". My own years of experience since then have validated this as a very functional and efficient technique.

I have also been working on something along this concept... I took a queue from Apache::Dispatch and Maypole which act as mod_perl handlers that then give the work to some controller class based on the path...

I'm currently calling it C::A::Dispatch. It based on the path it would
create an instance of the correct class, give it the right run mode, and
then run it...

So a request for something like this...
   /app/user_preferences/mode2

would be translated basically into these steps...
   require User::Preferences;
   my $app = User::Preferences->new();
   $app->mode_param(sub {return 'mode2'});
   $app->run();

I really like it cause there are no instance scripts. I know somepeople
really like instance scripts but to me they seem like clutter. I have
found that if move all configuration directives into config files they
are easier for non programmers to edit and then I don't need instance
scripts.

I don't know how much interest there would be from other people for
something like this, but I'm willing to listen. Also, if there is a way
for this to done in a normal CGI env (non mod_perl) then I'd be willing
to do that as well if there was an interest. Maybe ...
index.cgi?rm=user_preferences/mode2 or something like that...

My code has been updated a bit since then. Here's what it looks like
now:

#####

sub cgiapp_init {
my $self = shift;
$self->mode_param(\&get_mode_param);
}
# This function provides another way to get the CGI::App run mode
# Use the first piece of PATH_INFO, or fall back to the usual technique.
sub get_mode_param {
my $self = shift;
my $pi = $ENV{PATH_INFO};
# remove the leading slash
$pi =~ s!^/!!;
# just grab the first field
$pi = (split q'/', $pi)[0];
return (length $pi) ? $pi : $self->query->param('rm');
}


########

I would like to again propose that support for this technique be added
to CGI::App directly. It could be done by publishing "get_mode_param" as
a plugin, but I think it's reasonable for inclusion in the core.

Here's what I have in mind for the API:


$self->mode_param('rm', path_info => 1);

I like the idea, but I'm not always happy with passing in parameters where some are name-value and others aren't. Just to look at other options we could have

  $self->mode_param(path_info => 1, default_param => 'rm');

and then detect the number of args on the other side... or we could
introduce a new method altogether like...

  $self->mode_from_path(1);

This would be used in conjunction with the mode_param() where if
mode_from_path was true and we could get the mode from the path then we
use it, else we use the regular mode_param. We could even add a new key
to pass to new MODE_FROM_PATH => 1... just another idea to
consider...but I like the idea overall.

This should be backwards compatible with the current options.

As would both of my suggestions.

--
Michael Peters
Developer
Plus Three, LP



--
Michael Peters
Developer
Plus Three, LP


--------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to