geektron has asked for the wisdom of the Perl Monks concerning the following question:

so after posting this thread ( CGI::Application, inheritance trees, and 'the right way' ) i decided it was time to dig into CGI::Application::Dispatch, and it seems to be a great thing. most things "just work" ... as long as i've tacked on the module information in the path for GET/POST requests.

but now i'm stuck on *one* last thing. setting a "default" dispatch.

this works for a non-logged-in user:  /cgi-bin/myapp.cgi/SiteManager to take them to the login page.

I'd like to get that work work w/out the module name tacked onto the end ... if that's going to be possible. the perldoc for CGI::Application::Dispatch is a little sparse, and i understand that it's alpha SW ...

anyone tried to do this and been successful?

Replies are listed 'Best First'.
Re: CGI::Application::Dispatch and 'default' run-modes
by tachyon (Chancellor) on Nov 03, 2004 at 00:45 UTC

    This module has a significant issue in that it does not let you set a default module and a default runmode if these are not passed. It needs patching to do so. It looks quite handy so I have patched it to accept default values (untested as yet). You would have to subclass all bar one function in it to get the same result so you really need to patch it. It looks like the author has not considered a desire for default behaviour.

    103a104,106 > PerlSetVar CGIAPP_DEFAULT_RM Login > # Some::Module or Some_Module syntax OK > PerlSetVar CGIAPP_DEFAULT_DISPATCH Some_Module 123c126 < my $module = get_module_name($path, $dir_args->{CGIAPP_DISPATCH_ +PREFIX}); --- > my $module = get_module_name($path, $dir_args->{CGIAPP_DISPATCH_ +PREFIX}, $dir_args->{CGIAPP_DEFAULT_DISPATCH} ); 147c150 < my $rm = get_runmode($path); --- > my $rm = get_runmode($path, $dir_args->{CGIAPP_DEFAULT_RM}); 169a173,174 > DEFAULT_MODULE => 'Some_Module', # Some::Module or Some +_Module OK > DEFAULT_RM => 'Login', 192c197,198 < ($args{CGIAPP_DISPATCH_PREFIX} || $args{PREFIX}) --- > ($args{CGIAPP_DISPATCH_PREFIX} || $args{PREFIX}, > $args{CGIAPP_DEFAULT_MODULE} || $args{DEFAULT_MODULE} ) 203c209 < my $run_mode = get_runmode($ENV{PATH_INFO}); --- > my $run_mode = get_runmode($ENV{PATH_INFO},$args{CGIAPP_DEFA +ULT_RM}||$args{DEFAULT_RM}); 222c228 < my ($path, $prefix) = @_; --- > my ($path, $prefix, $default ) = @_; 226a233 > $module ||= $default; 230c237 < $module = join( '::', ( map { ucfirst } ( split( /_/, $modul +e ) ) ) ); --- > $module = join( '::', ( map { ucfirst } ( split( /[_:]+/, $m +odule ) ) ) ); 249c256,258 < return (split(/\//, shift))[2]; --- > my ( $path, $default ) = @_; > my $rm = (split(/\//, $path))[2]; > return defined $rm ? $rm : $default;

    Seve as patch.txt, then run patch Dispatch.pm < patch.txt. Obviously this is if you are in the same dir as Dispatch.pm

    cheers

    tachyon

Re: CGI::Application::Dispatch and 'default' run-modes
by PodMaster (Abbot) on Nov 03, 2004 at 00:12 UTC
    You've got tunnel vision :)
    if( length $ENV{QUERY_STRING} ){ print "Status: 302 Moved\015\012Location: $ENV{SCRIPT_NAME}/SiteMana +ger\015\012\015\012" } else { CGI::Application::Dispatch->dispatch(); }
    If that's not what you want, then read the documentation more carefully, subclass CGI::Application::Dispatch and override the appropriate method.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      well, i was trying to avoid something like this ... i know that i could do a redirect there, or a mod_rewrite trick, but i was trying to avoid it unless that's what i *absolutely* had to do.

      i'll try the patch, and if i can't get that to work, then i'll just use some redirect tricks.

Re: CGI::Application::Dispatch and 'default' run-modes
by mpeters (Chaplain) on Nov 04, 2004 at 17:58 UTC
    hello all, I am the author of C::A::Dispatch and someone pointed me towards this discussion. I am working on getting the below patch integrated with docs, testing, and other patches I have recieved. I noticed that you said the perldoc is a little sparse... How would you improve it ? I'm always looking for suggestions. Thanks
      well, we can take the additions to the perldoc offline, if you want ... i'd have to look back at it (it's been a couple days now, and my brain is in other places).

      burnout @ comradeburnout dot com

      i'd be more than willing to help add to the docs, make it a better module. so far i'm in love with it.