Michael Peters wrote:
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...
I would be interested to see how you implemented this. Sounds really useful for some of the apps I'm maintaining.
Well, in brief it's something like this...
in httpd.conf
<Location /app> SetHandler perl-script PerlHandler CGI::Application::Dispatch
#using C::A::Plugin::Config::Simple PerlSetEnv CGIAPP_CONFIG_FILE /sites/mysite/myconf.ini
#C::A::Dispatch PerlSetEnv CGIAPP_DISPATCH_PREFIX MySite </Location>
CGIAPP_DISPATCH_PREFIX is something to tack onto the module name before requiring it and creating a new one.
so given a url like /app/user_perferences/mode2
apache sends it to C::A::Dispatch cause of the Location /app in the httpd.conf. Then C::A::C sees the 'user_preferences' and turns it into 'User::Preferences' and then prefixes that with the CGIAPP_DISPATCH_PREFIX and it become 'MySite::User::Preferences'.
It's then created (via new()) and run (via run()).
I should have some code to show shortly.
HTH
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();
How do you map path elements to the correct C::A class?
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 would be very happy with such a setup.
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...
Currently I resort to using mod_rewrite, doing stuff (roughly) like
RewriteRule ^/site/([^/]+) /cgi-bin/script.pl?rm=$1 [PT]
which works fine under mod_cgi too.
I can't think of a way to do without some form of instance script (or dispatcher) in a normal CGI environment though.
Rhesa
--------------------------------------------------------------------- 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]
-- 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]
