- 论坛徽章:
- 0
|
Catalyst 内置了web服务器,看来使用Nginx作为生产环境的Web服务器比较好,一直没有搞清楚两者如何结合?
看了一些资料,感觉Nginx通过配置和一个fastcgi后台运行的守护进程进行交互,由这个守护进程和catalyst框架通讯实现。
还有一个疑问,如果我的前端使用dojo toolkit,这个框架直接在那些tt2文件中使用就可以了。看起来简单,但是整体的各个组件如何相互协作需要搞清楚?
我咨询了Catalyst的作者,他是这样回答的:
Catalyst, unlike a framework like say Ruby on Rails, sits at the center of a number of other Perl technologies. You named a few, such as Plack/PSGI, Template Toolkit, etc. Others might include DBIx::Class for interfacing with a database. And of course any number of testing tools on the Test::* namespace. As a result you have to put together a stack that makes sense to you, although one of the more common ones would be those mentioned.
Plack is an implementation of the PSGI specification, which connections a web application (such as Catalyst) to a web server, such as Nginx, Apache, Starman, etc. This glue layer is reusable across many web frameworks, so we all work on it together for the betterment of all. Plack also implements common middleware for concerns that are cross cutting, such as session and cookie management, authentication, etc. Some web frameworks make heavy use of middleware, such as Web::Simple, while Catalyst tends to mix and match between middleware and pre-existing Catalyst specific components. For example, Catalyst has its own mature session and authentication components, so we tend to use that rather than the Plack middleware (although over time I'd personally like to move towards using more middleware).
Template Toolkit (TT) is a templating system which is a common choice for a View layer in Catalyst. It allows you a more cleanly expressive approach to the concern of how your web pages look. Quite often you will use a Javascript framework, such as Dojo, Jquery or Angular.js to name a few of the ones I am personally familiar with. Javascript will be integrated into the View (TT). Catalyst, unlike some web frameworks, doesn't offer a lot of Javascript code generation tools since most Perl programmers prefer a more hands on approach and write their Javascript manually. Catalyst offers some tools for interacting with a Javascript application, such as support for JSON. So using Javascript with Catalyst is totally fine, just as I said compared to some frameworks you might find yourself needing to write a bit more manual code. As I said, Perl programmers tend to like to be 'close to the metal' so that is reflected in how Catalyst works.
I recommend you look at a few Catalyst applications on Github and review the tutorial if you can.
FastCGI is great, and my first choice for production systems. Plack implements PSGI and offers you a way to integrate a server such as FastCGI with your Catalyst web application. It also lets you 'glue' that same application to a different server. For example, many people use Starman as a server for development be cause its very easy to setup, but use something else in production (although Starman if run behind a proxy can be solid in production as well and some people choose that setup).
[client web browser] <--> [Apache <--> FastCGI] <--> [Plack FastCGI Handler <--> Catalyst <--> DBIx::Class <--> Database]
^^ is one example stack.
Here's a great blog of someone that started with Catalyst from the start and he did his best to record the journey. Maybe it will help you.
http://blogs.perl.org/users/j0e/
Also, I recommend reading the current and past Advent Calendars:
http://www.catalystframework.org/calendar/
You are welcome!
Best of luck! --jnap
欢迎指导! |
|