Alex Tokarev > Plack-Middleware-ExtDirect-2.00 > Plack::Middleware::ExtDirect



Annotate this POD

View/Report Bugs
Module Version: 2.00   Source   Latest Release: Plack-Middleware-ExtDirect-2.01


Plack::Middleware::ExtDirect - RPC::ExtDirect gateway for Plack


In your plackup, before Plack::Runner->run():

 use My::Server::Side::Class;
 use My::Server::Side::Class2;

In your app.psgi:

 my $app = sub { ... };
 builder {
    enable 'ExtDirect', api_path     => '/extdirect_api',
                        router_path  => '/extdirect_router',
                        poll_path    => '/extdirect_events',
                        remoting_var => '',
                        polling_var  => '',
                        namespace    => 'myApp',    # Defaults to empty
                        auto_connect => 0,
                        no_polling   => 0,
                        debug        => 0,
                        before       => \&global_before_hook,
                        after        => \&global_after_hook,


This module provides RPC::ExtDirect gateway implementation for Plack environment. It is packaged as standard Plack middleware component suitable for use with Plack::Builder.

You can change some default configuration options by passing corresponding parameters like shown above. For the meaning of parameters, see RPC::ExtDirect::API documentation.

Note that Ext.Direct specification requires server side implementation to return diagnostic messages only when debugging is explicitly turned on. This is why debug flag defaults to 'off' and RPC::ExtDirect returns generic error messages that do not contain any details as to where and what error has happened.


Attribute handlers

For RPC::ExtDirect attribute handlers to work properly, modules that expose ExtDirect Methods should be loaded at compile time. On the other hand, Plack::Runner loads and compiles code in *.psgi at runtime, and that breaks attribute magic dust. To avoid this, make sure you load all modules that provide Ext.Direct functionality - including Event providers - before Plack::Runner starts. The easiest way to do this is to copy plackup script and modify it a little to use all relevant modules in it.

See included code examples to see how it works.

Environment object

For Plack Ext.Direct gateway, the environment object is based on Plack::Request. While it does provide the same methods described in "ENVIRONMENT OBJECTS" in RPC::ExtDirect, behavior of these methods can be slightly different from CGI environment. For example, $env->http() in CGI will return the list of both environment variables and HTTP headers in upper case, while the same $env->http() in Plack application will return only HTTP headers as they were defined in HTTP spec. To avoid problems, always find the actual header name first and then use it:

    my ($header) = grep { /^Content[-_]Type$/i } $env->http();
    my $value    = $env->http($header) if $header;


Plack::Middleware::ExtDirect is dependent on the following modules: Plack, RPC::ExtDirect, JSON, Attribute::Handlers.


For more information on core functionality see RPC::ExtDirect.

For more information on Ext.Direct API see specification: and documentation:!/api/

See included ExtJS examples for ideas on what Ext.Direct is and how to use it.


There are no known bugs in this module. To report bugs, use github RT (the best way) or just drop me an e-mail. Patches are welcome.


Alexander Tokarev <>


I would like to thank IntelliSurvey, Inc for sponsoring my work on version 2.0 of RPC::ExtDirect suite of modules.


Copyright (c) 2011-2012 Alexander Tokarev.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

Included ExtJS examples are copyright (c) 2011, Sencha Inc. Example code is used and distributed under GPL 3.0 license as provided by Sencha Inc. See

syntax highlighting: