[cgiapp] problem w/ CGI::Application::Server and ...::Dispatch and a fix

George Hartzell hartzell at alerce.com
Sat Sep 13 15:06:36 EDT 2008


I was chasing a bug in CGI::Application::Dispatch::Server this morning
and thought I should revisit CGI::Application::Server, which has
support for CGI::Application::Dispatch entry points which I'd never
test driven (I think it was added after
CGI::Application::Dispatch::Server happened).

I couldn't make the example in the synopsis work, and couldn't even
get it to work when I used something like

  '/account' => 'CGI::Application::Dispatch',

The problem is in CGI::Application::Server::handle_request, where it
tests

  if ($target->isa('CGI::Application::Dispatch')) ...

I think that isa only works with packages that bless objects into some
class, which isn't how CGI::Application::Dispatch works.

A quick simple test of that theory is to add a "use MyDispatch;" to
the script in the synopsis, add this entry point

  '/account' => MyDispatch',

and then change the test to:

  if ($target->can('dispatch')) ...

A friendlier/more complete solution is to not require the 'use'
statement (like we don't for CGI::Application based entry points) and
require the class ourselves.

I'm attaching a gzipped tarball that contains a modified
CGI::Application::Server.pm (original code commented out) in which the
section is rewritten to first try the CGI::Application possibility,
then try the CGI::Application::Dispatch possibility (requiring the
class and using can()), then finally whining if nothings worked.

Has anyone else had any luck using CGI::Application::Server with
CGI::Application::Dispatch classes?  If so, then I'm confused.

If not, do things work better using my attached change?

Thanks,

g.



More information about the cgiapp mailing list