The debug middleware offers a configurable set of panels that displays information about the current request and response. The information is generated only for responses with a status of 200 (OK) and a Content-Type that contains text/html or application/xhtml+xml and is embedded in the HTML that is sent back to the browser. Also the code is injected directly before the </body> tag so if there is no such tag, the information will not be injected.

To enable the middleware, just use Plack::Builder as usual in your .psgi file:

The Debug middleware takes an optional panels argument whose value is expected to be a reference to an array of panel specifications. If given, only those panels will be enabled. If you don't pass a panels argument, the default list of panels - Environment, Response, Timer, Memory, Session and DBITrace - will be enabled, each with their default settings, and automatically disabled if their targer modules or middleware components are not loaded.

The Debug middleware is designed to be easily extensible. You might want to write a custom debug panel for your framework or for your web application. Each debug panel is also a Plack middleware copmonent and is easy to write one.

Let's look at the anatomy of the Timer debug panel. Here is the code from that panel:

To write a new debug panel, place it in the Plack::Middleware::Debug:: namespace. In our example, the Timer panel lives in the Plack::Middleware::Debug::Timer package.

The only thing your panel should do is to subclass Plack::Middleware::Debug::Base. This does most of the things a middleware component should do as a Plack middleware, so you only need to override run method to profile and create the panel content.

You can create as many lexical variables as you need and reference that in the returned callback as a closure, and update the content of of the $panel which is Plack::Middleware::Debug::Panel object.

In our Timer example we want to list three key/value pairs: the start time, the end time and the elapsed time. We use the render_list_pairs() method to place the pairs in the order we want. There is also a render_hash() and render_lines() method, to render a hash keys and values, as well as just text lines (e.g. log messages).