如何将 Catalyst 请求转交给 CGI::Application?

How do I hand off a Catalyst request to CGI::Application?

我有一个像

这样的 CGI::Application 循环
while (my $q = new CGI::Fast){                                     
  S::W::Dispatch->dispatch(args_to_new => { QUERY => $q });
  my $webapp = S::W::instance();                           

  undef $CGI::Application::INSTANCE;                               
  S::W::instance(undef);                                   
  S::clear_instance();                                          
}

并且,简而言之,我想将其作为新的 Catalyst 调度..

所以我想做这样的事情

sub oldRoot :Local {
  ...
  S::W::Dispatch->dispatch(args_to_new => { QUERY => $q });
}

所以我需要知道如何在 Catalyst 中重建 $q。这很容易做到吗?或者,如何更轻松地实现这一目标?

这实际上比我预期的要容易得多。

只需让您的控制器扩展 Catalyst::Controller::WrapCGI,而不是 Catalyst::Controller

BEGIN { extends 'Catalyst::Controller::WrapCGI' }

然后像这样包装整个东西..

$self->cgi_to_response($c, sub {                                    
  my $q = new CGI::Fast;                                            
  S::W::Dispatch->dispatch(args_to_new => { QUERY => $q }); 
  my $webapp = S::W::instance();                            
  undef $CGI::Application::INSTANCE;                                
  S::W::instance(undef);                                    
  S::clear_instance();                                           
} );

刚刚好..