[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] feedback on CGI::Application::Dispatch


I just tried out the developer release of CGI::Application::Dispatch
2.00, and I have to say I really like it.  It helped me to create
shorter, cleaner, URLs for my project, pulling together a larger
dynamic website in something more friendly. 

I thought it would be helpful to share an actual dispatch script I
created to use with it. (Sorry, the corresponding website is not yet
public. )

One thing that comes of this use is that it would be nice to override 
TMPL_PATH easily, without supplying a whole copy of "args_to_new" to do
that. 

Hopefully this spur some ideas about how we can further improve the
dispatcher, or I can I simply my own code!

    Mark

#############

#!/usr/bin/perl
use strict;
use warnings;
use FindBin (qw/$Bin/);
use lib ("$Bin/../../perllib");

# mod_rewrite screws with the PATH_INFO by turning it into a file system path,
# so we unscrew it.
  use Cwd 'abs_path'; 
  chdir $Bin;
  # Location of the www root in relation to the dispatcher
  my $www = abs_path("../");
  # fix /home versus /usr/home difference
  $www =~ s{/usr}{};
  # the final removal of the file system stuff mod_rewrite added.
  $ENV{PATH_INFO} =~ s/^$www//g;

my %default_params = (
    # This flag is used to turn off
    # the call to mode_param in my super class, 
    # which would undo the run mode setting that the dispatcher does with its own call
    # to mode_param
    # (Perhaps the dispatcher should always set a param like this by default).
    using_dispatcher_p => 1,
    config_files => ['../../config/Config.pl'],
    zone => 'guest',
);

my %event_args = (
    app       => 'Event',
    args_to_new => {
        TMPL_PATH => 'events/',
        PARAMS    => \%default_params,
    }
);

my %auth_args = (
    app       => 'Auth',
    args_to_new => {
        TMPL_PATH => 'auth/',
        PARAMS    => \%default_params,
    }
);

use CGI::Application::Dispatch;
CGI::Application::Dispatch->dispatch(
     debug => 0,
     prefix  => 'Project',
     args_to_new => {   
         PARAMS => \%default_params,
     },
     # Let's keep this at least roughly alphabetical, Yo!
     # Remember, first match wins, so shorter URLs go at the bottom
     table   => [
         # For the "auth" run modes, I like the internal run mode names,
         # so one entry covers them all.
         'account/:rm?'            => { %auth_args  }, 

         # For Events I have lots of entries to shorten the names more.
         'event/:event_id/detail' => { %event_args, rm => 'event_detail' }, 
         'event/add'              => { %event_args, rm => 'event_add_form' }, 
         'event/add_process'      => { %event_args, rm => 'event_add_process' }, 
         'event/cal'              => { %event_args, rm => 'cal_view' },
         'event/day'              => { %event_args, rm => 'event_date_detail' }, 
         'event/edit'             => { %event_args, rm => 'event_edit_form' }, 
         'event/edit_process'     => { %event_args, rm => 'event_edit_process' }, 
         'event/feed'             => { %event_args, rm => 'rss' }, 
         'event/month/:year?/:mon?' => { %event_args, rm => 'month_view' },
         'event/suggest'          => { %event_args, rm => 'suggest_display', app => 'EventSuggest' },
         'event/suggest_process'  => { %event_args, rm => 'suggest_process', app => 'EventSuggest' },
         'event/suggest_report'   => { %event_args, rm => 'suggest_report_display', app => 'EventSuggest' },
         'event/suggest_report_process' => { %event_args, rm => 'suggest_report_process', app => 'EventSuggest' },
         'event/week'             => { %event_args, rm => 'week_view' }, 
         'event/:rm?'              => { %event_args, }, 
     ],
);

############

For the best experience, I recommend getting a copy of the latest from
the Subversion repo, or waiting for the next release-- some usual
changes arrived over the weekend.

    Mark

















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


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.