如何将静态 CGI 风格的 perl 脚本(xxx.pl) 转换为动态 PSGI 应用程序?
CGI 风格的 Perl 脚本很难用这种风格进行测试:(
def test_it_says_hello_to_a_person
get '/home.pl', :name => 'Simon'
assert last_response.body.include?('Simon')
end
注意:代码是用 ruby 编写的,使用 Rack::Test
)。
但是如果我可以将静态文件转换为 PSGI 应用程序 (代码参考,接受 $env
作为参数,返回 [$status, $header, $body]
),事情会很简单,并且 Plack::测试将完成剩下的工作。
我正在阅读 PSGI 规范,通常我可以看到通往此的路线。但我还是想知道这有轮子的存在吗?
另外,我认为 Plack::Test
的界面不如 Rack::Test
漂亮,有替代方案吗?
CGI-style perl scripts are hard to test in this style:
def test_it_says_hello_to_a_person
get '/home.pl', :name => 'Simon'
assert last_response.body.include?('Simon')
end
(Note: the code is in ruby, using Rack::Test
).
But if I can turn static file to a PSGI application
(A code reference, accept $env
as parameter, return [$status, $header, $body]
), things will be easy, and Plack::Test
will do the rest.
I am reading PSGI specification, generally I can see the route to this. But I still want to know is there any existence wheel to this?
Also, I think Plack::Test
's interface is not as beautiful as Rack::Test
, any Alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你想看看 Plack::App::WrapCGI。当你给它一个 Perl 脚本作为参数时,它使用类似于 ModPerl::Registry 将您的 CGI 脚本编译为 PSGI 应用程序。即使它不知道如何做到这一点,它也有能力从 PSGI 环境模拟完整的 CGI 环境,这意味着它可以分叉并执行真正的 CGI 脚本(甚至是用另一种语言编写的脚本)并且在任何类型的 Plack 处理程序下运行它,包括 Plack::Test。
I think you want to look at Plack::App::WrapCGI. When you give it a Perl script as an argument, it uses a technique similar to ModPerl::Registry to compile your CGI script into a PSGI app. And even if it can't figure out how to do that, it has the ability to emulate a complete CGI environment from a PSGI environment, meaning that it can fork and exec a bona fide CGI script (even one written in another language) and run it under any sort of Plack handler, including Plack::Test.