PSGI: What is it and what's the fuss about?

前端 未结 3 1140
感情败类
感情败类 2020-12-24 02:59

I have been trying to decide if my web project is a candidate for implementation using PSGI, but I don\'t really see what good it would do for my application at this stage.<

相关标签:
3条回答
  • 2020-12-24 03:30

    Borrowing from a recent blog post by chromatic, Why PSGI/Plack Matters (Testing), here's what it is:

    It's a good idea borrowed from Python's WSGI and Ruby's Rack but made Perlish; it's a simple formalizing of a pattern of web application development, where the entry point into the application is a function reference and the exit point is a tuple of header information and a response body.

    That's it. That's as simple as it can be, and that simplicity deceives a lot of people who want to learn it.

    An important benefit is, ibid.,

    Given a Plack application, you don't have to deploy to a web server—even locally—to test your application as if it were deployed … Plack and TWMP (and Plack::Test) use the well-defined Plack pattern to make something which was previously difficult into something amazingly easy. They're not the first and they won't be the last, but they do demonstrate the value of Plack.

    0 讨论(0)
  • 2020-12-24 03:51

    Forget the Apache bit. It's a way of writing your application so that the choice of webserver becomes less relevant. At $work we switched to Plack/PSGI after finding our app running with very high CPU load after upgrading to Apache2 - benchmarking various Apache configs and NYTProf'ing were unable to determine the reason, and using PSGI and the Starman webserver worked out much better for us.

    Now everything is handled in one place by our PSGI app (URL re-writes, static content, expiry headers, etc) rather than Apache configuration, so it's a) Perl, and b) easily tested via our standard /t/ scripts. Also our tests are now testing exactly what a user sees, rather than just the basic app itself.

    It may well not be relevant to you if you're happy with Apache and mod_perl, and I'm sure others will be able to give much better answers, but for us not having to deal with anything Apache-related again is such a relief in itself. The ease of testing, and the ability to just stick in a Data::Dumper and see what's going on rather than wrestling with ModRewrite and friends, is a great boon.

    0 讨论(0)
  • 2020-12-24 03:54

    Started wrote an answer and after 50 lines I deleted it. Simply because it is impossible tell (in short) why is PSGI extremely cool. I'm new in PSGI too, but zilion things now are much easier as before in my apache/mod_perl era.

    I can give you next advices:

    1. read the Plack advent calendar - all days, step-by-step. You must understand the basic philosophy, what is good on onions and so on... :)
    2. search CPAN for "Plack::Middleware::" - and read the first few lines in each. Here are MANY. (Really should be somewhere some short overview for each one, unfortunately don't know any faster way. Simply it is good to know, what middlewares are already developed. (For example, you sure will need the Plack::Middleware::Session, or Plack::Middleware::Static and so on...)
    3. read about Plack::Builder (already done, when you done with the advent calendar) :)
    4. try write some apps with it and will find than Plack is like the first sex - now you didn't understand that you could live without it.

    ps: If was here something like "Perl Oscar", will sure nominating MyiagavaSan. :)

    0 讨论(0)
提交回复
热议问题