Dancer: 优雅的Perl web框架,推荐!
主页: http://dancer.sukria.net/
作者: sukria,是日本某公司的CTO,知名CPANer
创意: 来自于Ruby的一个框架Sinatra
例子:
| #!/usr/bin/perl use Dancer; get ‘/hi’ => sub { “Hello World!” }; dance; |
然后就可以独立运行了:
| $ perl ./hi.pl >> Listening on 127.0.0.1:3000 == Entering the dance floor … == GET /hi HTTP/1.0 200 OK |
在浏览器里输入 http://your_host:3000/hi/就可以看到Helloworld字样了。默认端口是3000.
这是作者主页的整个代码:
| #!/usr/bin/perl use Dancer; use Template; my @pages = qw(quickstart documentation contribute about example); get ‘/’ => sub { template ‘home’; }; get ‘/:page’ => sub { my ($page) = params->{page}; pass and return false unless grep /$page/, @pages; template $page; }; get ‘/*’ => sub { status ‘not_found’; template ‘not_found’; }; dance; |
优势:
- 轻量级,可以在这个基础上继续开发;
- 优雅,符合直觉,比CGI::Application 更方便:
- 支持PSGI,可用于Apache等支持PSGI的server;
- 可以单独运行,standalone模式,作为Application Server;现在的默认httpd是http::server::simple。
- 支持模板dancer::template::simple和template::toolkit
问题:
我试用了一下,用simple模板可以,用TT的没有用,页面是空白,哪位用过指点下。
欢迎大家都来用。
发表评论
| Trackback
