View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Stevan Little > Web-Machine-0.04 > Web::Machine



Annotate this POD


New  1
Open  1
View/Report Bugs
Module Version: 0.04   Source   Latest Release: Web-Machine-0.17


Web::Machine - A Perl port of WebMachine


version 0.04


  use strict;
  use warnings;

  use Web::Machine;

      package HelloWorld::Resource;
      use strict;
      use warnings;

      use parent 'Web::Machine::Resource';

      sub content_types_provided { [{ 'text/html' => 'to_html' }] }

      sub to_html {
                  <title>Hello World Resource</title>
                  <h1>Hello World</h1>

  Web::Machine->new( resource => 'HelloWorld::Resource' )->to_app;


This is a port of Webmachine, actually it is much closer to the ruby version, with a little bit of the javascript version and even some of the python version thrown in for good measure.

It runs atop Plack, but since it really handles the whole HTTP transaction, it is not appropriate to use most middleware modules. (NOTE: I will write more about this in the future.)


This module is extremely young and it is a port of an pretty young (June 2011) module in another language (ruby), which itself is a port of a still kind of young module (March 2009) in yet another language (erlang). But that all said, it really seems like a sane idea and so I stole it and ported it to Perl.


NOTE: This module is a Plack::Component subclass and so follows the interface set forward by that module.

new( resource = $resource_classname, ?tracing => 1|0 )>

The constructor expects to get a $resource_classname and can take an optional tracing parameter which it will pass onto the Web::Machine::FSM.

inflate_request( $env )

This takes a raw PSGI $env and inflates it into a Plack::Request instance. By default this also uses HTTP::Headers::ActionPack to inflate the headers of the request to be complex objects.


This will create the Web::Machine::FSM object to run. It will get passed the value of the tracing constructor parameter.

create_resource( $request )

This will create the Web::Machine::Resource instance using the class specified in the resource constructor parameter. It will pass in the $request object and call new_response on the $request object to get a Plack::Response instance.

finalize_response( $response )

Given a $response which is a Plack::Response object, this will finalize it and return a raw PSGI response.

call( $env )

This is the call method overridden from the Plack::Component superclass.


If you set the WM_DEBUG environment variable to 1 we will print out information about the path taken through the state machine to STDERR.


Original Erlang -
Ruby port -
Node JS port -
Python port -


Stevan Little <>


This software is copyright (c) 2012 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.

syntax highlighting: