Permalink
Browse files

Merge pull request #874 from kentfredric/fix_env

Fix env
  • Loading branch information...
2 parents 4dd94f4 + 4f3d33b commit 6bac57ed01a3d4bf5f2ef82f687cef3e320310f3 @bigpresh bigpresh committed Dec 15, 2012
@@ -124,12 +124,12 @@ sub format_message {
my $fmt = $self->_log_format();
- $fmt =~ s{
+ $fmt =~ s^
(?:
\%\{(.+?)\}([a-z])|
\%([a-zA-Z])
)
- }{ $1 ? $block_handler->($1, $2) : $char_mapping->($3) }egx;
+ ^ $1 ? $block_handler->($1, $2) : $char_mapping->($3) ^egx;
return $fmt."\n";
}
View
@@ -138,16 +138,21 @@ sub to_string {
# helper for building a request object by hand
# with the given method, path, params, body and headers.
sub new_for_request {
- my ($class, $method, $uri, $params, $body, $headers) = @_;
- $params ||= {};
+ my ($class, $method, $uri, $params, $body, $headers, $extra_env) = @_;
+ $params ||= {};
+ $extra_env ||= {};
$method = uc($method);
my ( $path, $query_string ) = ( $uri =~ /([^?]*)(?:\?(.*))?/s ); #from HTTP::Server::Simple
- my $req = $class->new(env => { %ENV,
- PATH_INFO => $path,
- QUERY_STRING => $query_string || $ENV{QUERY_STRING} || '',
- REQUEST_METHOD => $method});
+ my $env = {
+ %ENV,
+ %{$extra_env},
+ PATH_INFO => $path,
+ QUERY_STRING => $query_string || $ENV{QUERY_STRING} || '',
+ REQUEST_METHOD => $method
+ };
+ my $req = $class->new(env => $env);
$req->{params} = {%{$req->{params}}, %{$params}};
$req->_build_params();
$req->{_query_params} = $req->{params};
View
@@ -299,6 +299,7 @@ sub _check_header {
sub dancer_response {
my ($method, $path, $args) = @_;
$args ||= {};
+ my $extra_env = {};
if ($method =~ /^(?:PUT|POST)$/) {
@@ -346,9 +347,9 @@ Content-Type: text/plain
my $l = 0;
$l = length $content if defined $content;
open my $in, '<', \$content;
- $ENV{'CONTENT_LENGTH'} = $l;
- $ENV{'CONTENT_TYPE'} = $content_type || "";
- $ENV{'psgi.input'} = $in;
+ $extra_env->{'CONTENT_LENGTH'} = $l;
+ $extra_env->{'CONTENT_TYPE'} = $content_type || "";
+ $extra_env->{'psgi.input'} = $in;
}
my ($params, $body, $headers) = @$args{qw(params body headers)};
@@ -357,12 +358,12 @@ Content-Type: text/plain
unless _isa($headers, "HTTP::Headers");
if ($headers->header('Content-Type')) {
- $ENV{'CONTENT_TYPE'} = $headers->header('Content-Type');
+ $extra_env->{'CONTENT_TYPE'} = $headers->header('Content-Type');
}
my $request = Dancer::Request->new_for_request(
$method => $path,
- $params, $body, $headers
+ $params, $body, $headers, $extra_env
);
# first, reset the current state
@@ -102,8 +102,8 @@ if ( (my ($pre, $version, $post)) = ($line =~ /^(\s*)(\S.*\S)(\s*)$/)) {
my $lpost = length $post;
$lpre and _fail("line starts with $lpre blank caracters, but it should not");
$lpost and _fail("line ends with $lpre blank caracters, but it should not");
- like($version, qr/^{{\$NEXT}}$|^\d\.\d{4}(_\d{2} | )\d{2}.\d{2}.\d{4}$/, "changelog line $line_nb: check version failed");
- $version =~ qr/^({{\$NEXT}})$|^\d\.\d{4}(_\d{2} | )\d{2}.\d{2}.\d{4}$/;
+ like($version, qr/^\{\{\$NEXT\}\}$|^\d\.\d{4}(_\d{2} | )\d{2}.\d{2}.\d{4}$/, "changelog line $line_nb: check version failed");
+ $version =~ qr/^(\{\{\$NEXT\}\})$|^\d\.\d{4}(_\d{2} | )\d{2}.\d{2}.\d{4}$/;
# print STDERR " -------> [$1] [$2]\n";
$current_version_is_dev = defined $1 || $2 =~ /^_\d{2}/;
@@ -25,7 +25,7 @@ use Dancer::Template::TemplateToolkit;
is(scalar(@error_lines), 3, "test verbose croak");
like($error_lines[0], qr!^core - template - '/not/a/valid/file' doesn\'t exist or not a regular file at!, "test verbose croak");
like($error_lines[1], qr!^\s*Dancer::Template::TemplateToolkit::render\('Dancer::Template::TemplateToolkit', '/not/a/valid/file'\) called at!, "test verbose croak stack trace");
- like($error_lines[2], qr!^\s*eval {...} called at (?:[.]/)?t/01_config/06_stack_trace.t!, "test verbose croak stack trace");
+ like($error_lines[2], qr!^\s*eval \{...\} called at (?:[.]/)?t/01_config/06_stack_trace.t!, "test verbose croak stack trace");
}
{
@@ -49,5 +49,5 @@ use Dancer::Template::TemplateToolkit;
is(scalar(@error_lines), 3, "test verbose croak");
like($error_lines[0], qr!^core - template - '/not/a/valid/file' doesn\'t exist or not a regular file at!, "test verbose croak");
like($error_lines[1], qr!^\s*Dancer::Template::TemplateToolkit::render\('Dancer::Template::TemplateToolkit', '/not/a/valid/file'\) called at!, "test verbose croak stack trace");
- like($error_lines[2], qr!^\s*eval {...} called at (?:[.]/)?t/01_config/06_stack_trace.t!, "test verbose croak stack trace");
+ like($error_lines[2], qr!^\s*eval \{...\} called at (?:[.]/)?t/01_config/06_stack_trace.t!, "test verbose croak stack trace");
}
@@ -20,7 +20,7 @@ Test::Output::stderr_like(
Test::Output::stderr_like(
sub { Dancer::Logger::warning( { this => 'that' } ) },
- qr/\[\d+\] warn @.+> {'this' => 'that'} in/,
+ qr/\[\d+\] warn @.+> \{'this' => 'that'\} in/,
'Hashref correctly serialized',
);
@@ -32,6 +32,6 @@ Test::Output::stderr_like(
Test::Output::stderr_like(
sub { Dancer::Logger::warning( { b => 1, a => 2, e => 3, d => 4, c => 5}) },
- qr/\[\d+\] warn @.+> {'a' => 2,'b' => 1,'c' => 5,'d' => 4,'e' => 3}/,
+ qr/\[\d+\] warn @.+> \{'a' => 2,'b' => 1,'c' => 5,'d' => 4,'e' => 3\}/,
'Hash keys are sorted okay',
);
@@ -68,7 +68,7 @@ SKIP: {
# with options
$data = { foo => { bar => { baz => [qw/23 42/] } } };
$json = to_json( $data, { pretty => 1 } );
- like $json, qr/"foo" : {/, "data is pretty!";
+ like $json, qr/"foo" : \{/, "data is pretty!";
my $data2 = from_json($json);
is_deeply( $data2, $data, "data is correctly deserialized" );

0 comments on commit 6bac57e

Please sign in to comment.