23 Jun 2016 20:26:04 UTC
- Distribution: Web-Machine
- Source (raw)
- Browse (raw)
- How to Contribute
- Repository (git clone)
- Issues (11)
- Testers (1867 / 40 / 0)
- KwaliteeBus factor: 1
- 88.13% Coverage
- License: perl_5
- Activity24 month
- Download (71.8KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:5 non-PAUSE usersDROLSKY Dave Rolsky
- Reverse dependencies
- CPAN Testers List
- Dependency graph
- Web::Machine IN A NUTSHELL
- Web::Machine and Plack
- COPYRIGHT AND LICENCE
Web::Machine::Manual - Learn how to use Web::Machine
The basic idea behind
Web::Machineis that the handling of a web request is implemented as a state machine. If you're not familiar with state machines, think of a flowchart. We look at the request and the resource we provide and ask questions about them. Is our service available? Is this a GET, POST, PUT, etc.? Does the request ask for a content type our resource provides?
The result of each question leads us to the next state (or flowchart box). Eventually we reach a point where we have a response for the client. Since this is all built on top of Plack and PSGI, the response consists of a status code, some headers, and an optional body.
The best way to understand the full request/response cycle is to look at the original Erlang webmachine state diagram. Each diamond in that diagram corresponds to a method that your Web::Machine::Resource subclass can implement. The return value from your method determines what method to call next.
However, unlike on that diagram, we often support return values beyond simple true/false values for methods. The Web::Machine::Resource documentation describes what each method can return.
Web::Machineimplements the complete request and response cycle, some Plack middleware is not really needed with
Web::Machine. For example, it wouldn't make sense to use something like
Web::Machineimplements the full content negotiation process, so if you want to handle requests for
text/htmlit probably makes more sense to do this in your resources. The benefit of doing so is that with
Web::Machineyou can easily ensure that you return a proper
406 Not Acceptablestatus for content types you can't handle.
There are still many pieces of Plack middleware that are useful with
Web::Machine, such as logging middleware, debugging/linting middleware, etc.
That all said,
Web::Machinewon't break if you use an inappropriate middleware; you'll just lose some of the benefits you get from implementing things the
The PSGI spec requires that the body you return contain bytes, not Perl characters. In other words, strings you return must be passed through
Encode::encodeso that Perl interprets their contents as bytes.
If your data is not binary or ASCII, your resource should make sure to provide
default_charset()methods. This will make sure that
Web::Machineknows how to turn your response bodies into bytes.
CAVEAT: Note that currently
Web::Machinedoes not provide full charset or encoding support when the body is returned as a CODE ref. This is a bug to be remedied in the future, but currently you are responsible for making sure this code ref returns bytes.
bugs may be submitted through https://github.com/houseabsolute/webmachine-perl/issues.
Stevan Little <firstname.lastname@example.org>
Dave Rolsky <email@example.com>
This software is copyright (c) 2016 by Infinity Interactive, Inc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.