1Web::Machine(3)       User Contributed Perl Documentation      Web::Machine(3)
2
3
4

NAME

6       Web::Machine - A Perl port of Webmachine
7

VERSION

9       version 0.17
10

SYNOPSIS

12         use strict;
13         use warnings;
14
15         use Web::Machine;
16
17         {
18             package HelloWorld::Resource;
19             use strict;
20             use warnings;
21
22             use parent 'Web::Machine::Resource';
23
24             sub content_types_provided { [{ 'text/html' => 'to_html' }] }
25
26             sub to_html {
27                 q{<html>
28                     <head>
29                         <title>Hello World Resource</title>
30                     </head>
31                     <body>
32                         <h1>Hello World</h1>
33                     </body>
34                  </html>}
35             }
36         }
37
38         Web::Machine->new( resource => 'HelloWorld::Resource' )->to_app;
39

DESCRIPTION

41       "Web::Machine" provides a RESTful web framework modeled as a state
42       machine. You define one or more resource classes. Each resource
43       represents a single RESTful URI end point, such as a user, an email,
44       etc. The resource class can also be the target for "POST" requests to
45       create a new user, email, etc.
46
47       Each resource is a state machine, and each request for a resource is
48       handled by running the request through that state machine.
49
50       "Web::Machine" is built on top of Plack, but it handles the full
51       request and response cycle.
52
53       See Web::Machine::Manual for more details on using "Web::Machine" in
54       general, and how "Web::Machine" and Plack interact.
55
56       This is a port of Webmachine <https://github.com/basho/webmachine>,
57       actually it is much closer to the Ruby version
58       <https://github.com/seancribbs/webmachine-ruby>, with a little bit of
59       the JavaScript version <https://github.com/tautologistics/nodemachine>
60       and even some of the Python version
61       <https://github.com/benoitc/pywebmachine> thrown in for good measure.
62
63       You can learn a bit about Web::Machine's history from the slides for my
64       2012 YAPC::NA talk <https://speakerdeck.com/stevan_little/rest-from-
65       the-trenches>.
66
67       To learn more about Webmachine, take a look at the links in the SEE
68       ALSO section.
69

METHODS

71       NOTE: This module is a Plack::Component subclass and so follows the
72       interface set forward by that module.
73
74       "new( resource => $resource_classname, ?resource_args => $arg_list,
75       ?tracing => 1|0, ?streaming => 1|0, ?request_class => $request_class )"
76           The constructor expects to get a $resource_classname, which it will
77           use to load and create an instance of the resource class. If that
78           class requires any additional arguments, they can be specified with
79           the "resource_args" parameter. The contents of the "resource_args"
80           parameter will be made available to the "init()" method of
81           "Web::Machine::Resource".
82
83           The "new" method can also take an optional "tracing" parameter
84           which it will pass on to Web::Machine::FSM and an optional
85           "streaming" parameter, which if true will run the request in a PSGI
86           <http://plackperl.org/> streaming response. This can be useful if
87           you need to run your content generation asynchronously.
88
89           The optional "request_class" parameter accepts the name of a module
90           that will be used as the request object. The module must be a class
91           that inherits from Plack::Request. Use this if you have a subclass
92           of Plack::Request that you would like to use in your
93           Web::Machine::Resource.
94
95       "inflate_request( $env )"
96           This takes a raw PSGI $env and inflates it into a Plack::Request
97           instance.  By default this also uses HTTP::Headers::ActionPack to
98           inflate the headers of the request to be complex objects.
99
100       "create_fsm"
101           This will create the Web::Machine::FSM object to run. It will get
102           passed the value of the "tracing" constructor parameter.
103
104       "create_resource( $request )"
105           This will create the Web::Machine::Resource instance using the
106           class specified in the "resource" constructor parameter. It will
107           pass in the $request object and call "new_response" on the $request
108           object to get a Plack::Response instance.
109
110       "finalize_response( $response )"
111           Given a $response which is a Plack::Response object, this will
112           finalize it and return a raw PSGI response.
113
114       "call( $env )"
115           This is the "call" method overridden from the Plack::Component
116           superclass.
117

DEBUGGING

119       If you set the "WM_DEBUG" environment variable to 1 we will print out
120       information about the path taken through the state machine to STDERR.
121
122       If you set "WM_DEBUG" to "diag" then debugging information will be
123       printed using Test::More's "diag()" sub instead.
124

SEE ALSO

126       The diagram - <https://github.com/Webmachine/webmachine/wiki/Diagram>
127       Original Erlang - <https://github.com/basho/webmachine>
128       Ruby port - <https://github.com/seancribbs/webmachine-ruby>
129       Node JS port - <https://github.com/tautologistics/nodemachine>
130       Python port - <https://github.com/benoitc/pywebmachine>
131       2012 YAPC::NA slides -
132       <https://speakerdeck.com/stevan_little/rest-from-the-trenches>
133       an elaborate machine is indispensable: a blog post by Justin Sheehy -
134       <http://blog.therestfulway.com/2008/09/webmachine-is-resource-server-for-web.html>
135       Resources, For Real This Time (with Webmachine): a video by Sean Cribbs
136       - <http://www.youtube.com/watch?v=odRrLK87s_Y>
137

SUPPORT

139       bugs may be submitted through
140       <https://github.com/houseabsolute/webmachine-perl/issues>.
141

AUTHORS

143       •   Stevan Little <stevan@cpan.org>
144
145       •   Dave Rolsky <autarch@urth.org>
146

CONTRIBUTORS

148       •   Andreas Marienborg <andreas.marienborg@gmail.com>
149
150       •   Andrew Nelson <anelson@cpan.org>
151
152       •   Arthur Axel 'fREW' Schmidt <frioux@gmail.com>
153
154       •   Carlos Fernando Avila Gratz <cafe@q1software.com>
155
156       •   Fayland Lam <fayland@gmail.com>
157
158       •   George Hartzell <hartzell@alerce.com>
159
160       •   Gregory Oschwald <goschwald@maxmind.com>
161
162       •   Jesse Luehrs <doy@tozt.net>
163
164       •   John SJ Anderson <genehack@genehack.org>
165
166       •   Mike Raynham <enquiries@mikeraynham.co.uk>
167
168       •   Nathan Cutler <ncutler@suse.cz>
169
170       •   Olaf Alders <olaf@wundersolutions.com>
171
172       •   Stevan Little <stevan.little@gmail.com>
173
174       •   Thomas Sibley <tsibley@cpan.org>
175
177       This software is copyright (c) 2016 by Infinity Interactive, Inc.
178
179       This is free software; you can redistribute it and/or modify it under
180       the same terms as the Perl 5 programming language system itself.
181
182
183
184perl v5.34.0                      2022-01-21                   Web::Machine(3)
Impressum