Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: a67fa01f97
Fetching contributors…

Cannot retrieve contributors at this time

100 lines (74 sloc) 2.491 kB
package Dancer::Handler::Debug;
use strict;
use warnings;
use HTTP::Headers;
use HTTP::Server::Simple::PSGI;
use base 'Dancer::Object', 'Dancer::Handler', 'HTTP::Server::Simple::PSGI';
use Dancer::Config 'setting';
use Dancer::Headers;
use Dancer::SharedData;
sub run {
my ($self, $req) = @_;
my ($method, $path, $query) = @ARGV;
my $host = "";
my $port = "3000";
my $env = {
'HTTP_ACCEPT' => '*/*',
'HTTP_HOST' => "$host:$port",
'HTTP_USER_AGENT' => 'curl',
'QUERY_STRING' => $query,
'REMOTE_ADDR' => "$host:$port",
'REMOTE_HOST' => "$host:$port",
'REQUEST_METHOD' => $method,
'REQUEST_URI' => $path,
'SERVER_NAME' => $host,
'SERVER_PORT' => $port,
'SERVER_SOFTWARE' => 'HTTP::Server::Simple/0.41',
'SERVER_URL' => "http://$host:$port/",
$req = Dancer::Request->new($env);
my $headers = HTTP::Headers->new(
'User-Agent' => 'curl',
'Host', "$host:$port",
'Accept', '*/*'
# now simulate a PSGI response for the current request only
my $res = eval { $self->{psgi_app}->($env) }
|| [500, ['Content-Type', 'text/plain'], ["Internal Server Error"]];
print "\n";
return $res;
sub start {
my ($self, $req) = @_;
print STDERR ">> Dancer dummy debug server\n" if setting('access_log');
my $dancer = Dancer::Handler::Debug->new();
my $psgi = sub {
my $env = shift;
my $req = Dancer::Request->new($env);
$dancer->{psgi_app} = $psgi;
sub dance { start(@_) }
=head1 NAME
Dancer::Handler::Debug - a debug handler for easy tracing
When developping a Dancer application, it can be useful to trace precisely what
happen when a query is processed. This handler is here to provide the developer
with a way to easily run the dancer application with the Perl debugger.
This handler will process ony one query, based on the first argument given on
the command line ($ARGV[0]).
=head1 USAGE
# in bin/
set apphandler => 'Debug';
# then, run the app the following way
perl -d bin/ GET '/some/path/to/test' 'with=parameters&other=42'
=head1 AUTHORS
Dancer contributors
Jump to Line
Something went wrong with that request. Please try again.