[cgiapp] ::Server vs ::Dispatch::Server: Worth having both?

George Hartzell hartzell at alerce.com
Wed Sep 17 16:26:20 EDT 2008


Bradley C Bailey writes:
 > Mark,
 > 
 > > CGI::Application::Dispatch::Server was released in Summer of '07, in part
 > > because CGI::Application::Server didn't have dispatching support.
 > > 
 > > But soon after, in the fall, CGI::Application::Server was released, which
 > > supports both dispatched and "regular" CGI::App entry points.
 > > 
 > > In reviewing the projects today, it seems likes CGI::Application::Server seems
 > > to cover all the bases. Is there any reason not to combine efforts and focus on
 > > just CGI::Application::Server ? 
 > > 
 > > As far as I can tell ::Dispatch::Server doesn't seem to offer much additional
 > > functionality, or a significantly different API.
 > > 
 > > Having both will certainly be confusing some new users now due to the similarity. 
 > > At a minimum, at least of them should document its differences and benefits over the other.
 > 
 > I fully agree here.  The impression I got is that since there is a 
 > CGI::Application::Dispatch::Server, then I must use that if I use CAD.
 > 
 > It's been a while since I looked at either closely, so I just looked at 
 > the source and here are my first opinions of what would need to be done 
 > to CA::Server to handle the way that I was using CAD::Server.
 > 
 > - Need a way to specify parameters to dispatch()
 > 
 > - Both handle output capturing different.  Is one better than the other?
 > 
 > - The order in which static files is served is different.
 > 
 > I set up my apps so that / is dispatched, but /static maps to static 
 > files.  Looking at CA::Server, it does not appear that this would be 
 > possible currently because it would always try and dispatch.  In 
 > CAD::Server it tries to serve files staticly first before sending to 
 > dispatch.  I think the best solution would be to specify a way to mark 
 > an entry point in the CA::Server config to specify static content.  Then 
 > I could do something like this:
 > 
 >    $server->entry_points({
 >        '/' => 'My::App::Dispatch',
 >        '/static' => undef,  # or maybe even pass a directory path to 
 > override document_root
 >    });
 > 
 > Other than these points the code looks to be basically the same.  I'd 
 > like to see them combined.

I think that it'd be great to retire
CGI::Application::Dispatch::Server once CGI::Application::Server
covers all of the bases.

I tried playing with it with my little demo app over last weekend and
got hung up on just the configuration described above.  I haven't
figured out whether it was my doing something wrong or whether what I
want to do doesn't work in CGI::Application::Server.

I often have url's like

  http://cgiapp:8080/Home/home

and dispatch them with My::App::Dispatch classes that look like this:

          table => [
                    # things under the css banner get run through
                    # the css run-mode.
		    # eg: http://hostname/css/my.css
		    #   app(package) is My::WebApp::CSS
		    #   run_mode is css (My::WebApp::CSS::css)
		    #   file is my.css
                    'css/:file' => {app => 'CSS',
                                    rm => 'css',
                                   },

		    # just match a single item and call it app
		    # eg: http://hostname/Home
		    #   app (package) is My::WebApp::Home
		    #   run_mode is whatever start mode Home declares.
                    ':app'      => {},

		    # match an app and a run_mode
		    # eg: http://hostname/Home/moose
		    #   app (package) is My::WebApp::Home
		    #   run_mode is moose (My::WebApp::Home::moose)
                    ':app/:rm'  => {},
                   ],

I tried setting it up like this:

     $server->entry_points({
         '/' => 'My::App::Dispatch',
     });
  
and couldn't get it to work.  Using url's like:

  http://cgiapp:8080/foo/Home/home 

and
     $server->entry_points({
         '/foo' => 'My::App::Dispatch',
     });

worked (some of the details above are from memory, I can't get to that
box from work).

I got to the point in valid_entry_point (I think...) where it loops
over the URI and it was exiting the while() loop without testing the
"empty" string after it chopped the last word off.

Does dispatching on '/' work for folks (was it operator error, or???)?
I can look into it a bit more over the weekend if it'd be useful.

If it isn't just me, then maybe just turning the while ($uri) {} into
do {} while($uri)?

If it is just me, anyone have a cluestick?

g.


More information about the cgiapp mailing list