| 1 | package Dancer::Test; | ||||||||||||||||||||||||||||||||||||
| 2 | 86 | our $AUTHORITY = 'cpan:SUKRIA'; | |||||||||||||||||||||||||||||||||||
| 3 | #ABSTRACT: Test helpers to test a Dancer application | ||||||||||||||||||||||||||||||||||||
| 4 | 86 | $Dancer::Test::VERSION = '1.3520'; | |||||||||||||||||||||||||||||||||||
| 5 | # test helpers for Dancer apps | ||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 86 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 86 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 86 | ▶ | use Test::Builder; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 86 | ▶ | use Test::More import => [ '!pass' ]; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 86 | ▶ | use Test::LongString; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | 86 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 14 | 86 | ▶ | use HTTP::Headers; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | 86 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 86 | ▶ | use Dancer ':syntax', ':tests'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 18 | 86 | ▶ | use Dancer::App; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 19 | 86 | ▶ | use Dancer::Deprecation; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 20 | 86 | ▶ | use Dancer::Request; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 21 | 86 | ▶ | use Dancer::Request::Upload; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 22 | 86 | ▶ | use Dancer::SharedData; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 23 | 86 | ▶ | use Dancer::Renderer; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 24 | 86 | ▶ | use Dancer::Handler; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 25 | 86 | ▶ | use Dancer::Config; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 26 | 86 | ▶ | use Dancer::FileUtils qw(open_file); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||
| 28 | 86 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 29 | 86 | ▶ | use vars '@EXPORT'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||
| 31 | 86 | @EXPORT = qw( | |||||||||||||||||||||||||||||||||||
| 32 | route_exists | ||||||||||||||||||||||||||||||||||||
| 33 | route_doesnt_exist | ||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | response_exists | ||||||||||||||||||||||||||||||||||||
| 36 | response_doesnt_exist | ||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | response_status_is | ||||||||||||||||||||||||||||||||||||
| 39 | response_status_isnt | ||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||
| 41 | response_content_is | ||||||||||||||||||||||||||||||||||||
| 42 | response_content_isnt | ||||||||||||||||||||||||||||||||||||
| 43 | response_content_is_deeply | ||||||||||||||||||||||||||||||||||||
| 44 | response_content_like | ||||||||||||||||||||||||||||||||||||
| 45 | response_content_unlike | ||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||
| 47 | response_is_file | ||||||||||||||||||||||||||||||||||||
| 48 | response_headers_are_deeply | ||||||||||||||||||||||||||||||||||||
| 49 | response_headers_include | ||||||||||||||||||||||||||||||||||||
| 50 | response_redirect_location_is | ||||||||||||||||||||||||||||||||||||
| 51 | response_redirect_location_like | ||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | dancer_response | ||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | read_logs | ||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | sub import { | ||||||||||||||||||||||||||||||||||||
| 59 | 85 | ▶ | my ($class, %options) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 60 | 85 | ▶ | $options{appdir} ||= '.'; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"appdir"} ||= "."
MC/DC100%1/1
$options{"appdir"} ||= "."
$options{"appdir"}
Truth table100%2/2
A
A= $options{"appdir"}
| |||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||
| 62 | # mimic PSGI env | ||||||||||||||||||||||||||||||||||||
| 63 | 85 | $ENV{SERVERNAME} = 'localhost'; | |||||||||||||||||||||||||||||||||||
| 64 | 85 | $ENV{HTTP_HOST} = 'localhost'; | |||||||||||||||||||||||||||||||||||
| 65 | 85 | $ENV{SERVER_PORT} = 80; | |||||||||||||||||||||||||||||||||||
| 66 | 85 | $ENV{'psgi.url_scheme'} = 'http'; | |||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||
| 68 | 85 | my ($package, $script) = caller; | |||||||||||||||||||||||||||||||||||
| 69 | 85 | $class->export_to_level(1, $class, @EXPORT); | |||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | 85 | Dancer::_init_script_dir($options{appdir}); | |||||||||||||||||||||||||||||||||||
| 72 | 85 | Dancer::Config->load; | |||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||
| 74 | # set a default session engine for tests | ||||||||||||||||||||||||||||||||||||
| 75 | 85 | setting 'session' => 'simple'; | |||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||
| 77 | # capture logs for testing | ||||||||||||||||||||||||||||||||||||
| 78 | 85 | setting 'logger' => 'capture'; | |||||||||||||||||||||||||||||||||||
| 79 | 85 | setting 'log' => 'debug'; | |||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||
| 82 | # Route Registry | ||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||
| 84 | sub _isa { | ||||||||||||||||||||||||||||||||||||
| 85 | 1200 | ▶ | my ( $reference, $classname ) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_isa: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||
| 86 | 1200 | ▶ | return blessed $reference && $reference->isa($classname); | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($reference) && $reference->isa($classname)
MC/DC50%1/2
builtin::blessed($reference) && $reference->isa($classname)
builtin::blessed($reference)
$reference->isa($classname)
Truth table66%2/3
A && B
A= builtin::blessed($reference)B= $reference->isa($classname)
| |||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||
| 89 | sub _req_to_response { | ||||||||||||||||||||||||||||||||||||
| 90 | 427 | ▶ | my $req = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_req_to_response: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||
| 92 | # already a response object | ||||||||||||||||||||||||||||||||||||
| 93 | 427 | ▶ | return $req if _isa($req, 'Dancer::Response'); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||
| 95 | 419 | ▶ | return dancer_response( ref $req eq 'ARRAY' ? @$req : ( 'GET', $req ) ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||
| 98 | sub _req_label { | ||||||||||||||||||||||||||||||||||||
| 99 | 274 | ▶ | my $req = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_req_label: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||
| 101 | 274 | ▶ | return _isa($req, 'Dancer::Response') ? 'response object' | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 102 | : ref $req eq 'ARRAY' ? join( ' ', @$req ) | ||||||||||||||||||||||||||||||||||||
| 103 | : "GET $req"; | ||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | sub expand_req { | ||||||||||||||||||||||||||||||||||||
| 107 | 54 | ▶ | my $req = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
expand_req: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 108 | 54 | ▶ | return ref $req eq 'ARRAY' ? @$req : ( 'GET', $req ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||
| 111 | sub route_exists { | ||||||||||||||||||||||||||||||||||||
| 112 | 43 | ▶ | my ($req, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
route_exists: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 113 | 43 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | 43 | my ($method, $path) = expand_req($req); | |||||||||||||||||||||||||||||||||||
| 116 | 43 | ▶ | $test_name ||= "a route exists for $method $path"; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$test_name ||= "a route exists for $method $path"
MC/DC100%1/1
$test_name ||= "a route exists for $method $path"
$test_name
Truth table100%2/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||
| 118 | 43 | $req = Dancer::Request->new_for_request($method => $path); | |||||||||||||||||||||||||||||||||||
| 119 | 43 | return $tb->ok(defined(Dancer::App->find_route_through_apps($req)), $test_name); | |||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||
| 122 | sub route_doesnt_exist { | ||||||||||||||||||||||||||||||||||||
| 123 | 4 | ▶ | my ($req, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
route_doesnt_exist: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 124 | 4 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||
| 126 | 4 | my ($method, $path) = expand_req($req); | |||||||||||||||||||||||||||||||||||
| 127 | 4 | ▶ | $test_name ||= "no route exists for $method $path"; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$test_name ||= "no route exists for $method $path"
MC/DC100%1/1
$test_name ||= "no route exists for $method $path"
$test_name
Truth table100%2/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||
| 129 | 4 | $req = Dancer::Request->new_for_request($method => $path); | |||||||||||||||||||||||||||||||||||
| 130 | 4 | return $tb->ok(!defined(Dancer::App->find_route_through_apps($req)), $test_name); | |||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||
| 133 | # Response status | ||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||
| 135 | sub response_exists { | ||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | Dancer::Deprecation->deprecated( | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_exists: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 137 | fatal => 1, | ||||||||||||||||||||||||||||||||||||
| 138 | feature => 'response_exists', | ||||||||||||||||||||||||||||||||||||
| 139 | reason => 'Use response_status_isnt and check for status 404.' | ||||||||||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||
| 143 | sub response_doesnt_exist { | ||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | Dancer::Deprecation->deprecated( | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_doesnt_exist: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 145 | fatal => 1, | ||||||||||||||||||||||||||||||||||||
| 146 | feature => 'response_doesnt_exist', | ||||||||||||||||||||||||||||||||||||
| 147 | reason => 'Use response_status_is and check for status 404.', | ||||||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||
| 151 | sub response_status_is { | ||||||||||||||||||||||||||||||||||||
| 152 | 160 | ▶ | my ($req, $status, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_status_is: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 153 | 160 | ▶ | $test_name ||= "response status is $status for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$test_name ||= "response status is $status for " . _req_label($req)
MC/DC0%0/2
$test_name ||= "response status is $status for " . _req_label($req)
$test_name
"response status is $status for " . _req_label($req)
Truth table66%2/3
A ||= B
A= $test_nameB= "response status is $status for " . _req_label($req)
| |||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||
| 155 | 160 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 156 | 160 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 157 | 160 | return $tb->is_eq($response->status, $status, $test_name); | |||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||
| 160 | sub response_status_isnt { | ||||||||||||||||||||||||||||||||||||
| 161 | 4 | ▶ | my ($req, $status, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_status_isnt: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 162 | 4 | ▶ | $test_name ||= "response status is not $status for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$test_name ||= "response status is not $status for " . _req_label($req)
MC/DC0%0/2
$test_name ||= "response status is not $status for " . _req_label($req)
$test_name
"response status is not $status for " . _req_label($req)
Truth table66%2/3
A ||= B
A= $test_nameB= "response status is not $status for " . _req_label($req)
| |||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||
| 164 | 4 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 165 | 4 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 166 | 4 | $tb->isnt_eq( $response->{status}, $status, $test_name ); | |||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||
| 169 | # Response content | ||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||
| 171 | sub response_content_is { | ||||||||||||||||||||||||||||||||||||
| 172 | 121 | ▶ | my ($req, $matcher, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_content_is: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 173 | 121 | ▶ | $test_name ||= "response content looks good for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$test_name ||= 'response content looks good for ' . _req_label($req)
MC/DC100%1/1
$test_name ||= 'response content looks good for ' . _req_label($req)
$test_name
Truth table100%2/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||
| 175 | 121 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 176 | 121 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 177 | 121 | return $tb->is_eq( $response->{content}, $matcher, $test_name ); | |||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||
| 180 | sub response_content_isnt { | ||||||||||||||||||||||||||||||||||||
| 181 | 4 | ▶ | my ($req, $matcher, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_content_isnt: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 182 | 4 | ▶ | $test_name ||= "response content looks good for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$test_name ||= 'response content looks good for ' . _req_label($req)
MC/DC0%0/1
$test_name ||= 'response content looks good for ' . _req_label($req)
$test_name
Truth table50%1/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||
| 184 | 4 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 185 | 4 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 186 | 4 | return $tb->isnt_eq( $response->{content}, $matcher, $test_name ); | |||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||
| 189 | sub response_content_like { | ||||||||||||||||||||||||||||||||||||
| 190 | 40 | ▶ | my ($req, $matcher, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_content_like: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 191 | 40 | ▶ | $test_name ||= "response content looks good for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$test_name ||= 'response content looks good for ' . _req_label($req)
MC/DC100%1/1
$test_name ||= 'response content looks good for ' . _req_label($req)
$test_name
Truth table100%2/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||
| 193 | 40 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 194 | 40 | return like_string( $response->{content}, $matcher, $test_name ); # better output for long content than Test::Builder | |||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||
| 197 | sub response_content_unlike { | ||||||||||||||||||||||||||||||||||||
| 198 | 4 | ▶ | my ($req, $matcher, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_content_unlike: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 199 | 4 | ▶ | $test_name ||= "response content looks good for " , _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$test_name ||= "response content looks good for "
MC/DC0%0/1
$test_name ||= "response content looks good for "
$test_name
Truth table50%1/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||
| 201 | 4 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 202 | 4 | return unlike_string( $response->{content}, $matcher, $test_name ); # better for long content than Test::Builder | |||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||
| 205 | sub response_content_is_deeply { | ||||||||||||||||||||||||||||||||||||
| 206 | 59 | ▶ | my ($req, $matcher, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_content_is_deeply: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 207 | 59 | ▶ | $test_name ||= "response content looks good for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$test_name ||= 'response content looks good for ' . _req_label($req)
MC/DC100%1/1
$test_name ||= 'response content looks good for ' . _req_label($req)
$test_name
Truth table100%2/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||
| 209 | 59 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||
| 210 | 59 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 211 | 59 | is_deeply $response->{content}, $matcher, $test_name; | |||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||
| 214 | sub response_is_file { | ||||||||||||||||||||||||||||||||||||
| 215 | 1 | ▶ | my ($req, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_is_file: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | $test_name ||= "a file is returned for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$test_name ||= 'a file is returned for ' . _req_label($req)
MC/DC0%0/1
$test_name ||= 'a file is returned for ' . _req_label($req)
$test_name
Truth table50%1/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||
| 218 | 1 | my $response = _get_file_response($req); | |||||||||||||||||||||||||||||||||||
| 219 | 1 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 220 | 1 | return $tb->ok(defined($response), $test_name); | |||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||
| 223 | sub response_headers_are_deeply { | ||||||||||||||||||||||||||||||||||||
| 224 | 7 | ▶ | my ($req, $expected, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_headers_are_deeply: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 225 | 7 | ▶ | $test_name ||= "headers are as expected for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$test_name ||= 'headers are as expected for ' . _req_label($req)
MC/DC100%1/1
$test_name ||= 'headers are as expected for ' . _req_label($req)
$test_name
Truth table100%2/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||
| 227 | 7 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||
| 228 | 7 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||
| 230 | 7 | is_deeply( | |||||||||||||||||||||||||||||||||||
| 231 | _sort_headers( $response->headers_to_array ), | ||||||||||||||||||||||||||||||||||||
| 232 | _sort_headers( $expected ), | ||||||||||||||||||||||||||||||||||||
| 233 | $test_name | ||||||||||||||||||||||||||||||||||||
| 234 | ); | ||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||
| 237 | # Sort arrayref of headers (turn it into a list of arrayrefs, sort by the header | ||||||||||||||||||||||||||||||||||||
| 238 | # & value, then turn it back into an arrayref) | ||||||||||||||||||||||||||||||||||||
| 239 | sub _sort_headers { | ||||||||||||||||||||||||||||||||||||
| 240 | 14 | ▶ | my @originalheaders = @{ shift() }; # take a copy we can modify | ||||||||||||||||||||||||||||||||||
|
Subroutine
_sort_headers: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 241 | 14 | my @headerpairs; | |||||||||||||||||||||||||||||||||||
| 242 | 14 | ▶ | while (my ($header, $value) = splice @originalheaders, 0, 2) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 243 | 40 | push @headerpairs, [ $header, $value ]; | |||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||
| 246 | # We have an array of arrayrefs holding header => value pairs; sort them by | ||||||||||||||||||||||||||||||||||||
| 247 | # header then value, and return them flattened back into an arrayref | ||||||||||||||||||||||||||||||||||||
| 248 | return [ | ||||||||||||||||||||||||||||||||||||
| 249 | 40 | map { @$_ } | |||||||||||||||||||||||||||||||||||
| 250 | 14 | ▶ | sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 251 | @headerpairs | ||||||||||||||||||||||||||||||||||||
| 252 | ]; | ||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||
| 256 | sub response_headers_include { | ||||||||||||||||||||||||||||||||||||
| 257 | 27 | ▶ | my ($req, $expected, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_headers_include: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 258 | 27 | ▶ | $test_name ||= "headers include expected data for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$test_name ||= 'headers include expected data for ' . _req_label($req)
MC/DC100%1/1
$test_name ||= 'headers include expected data for ' . _req_label($req)
$test_name
Truth table100%2/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 259 | 27 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||
| 261 | 27 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 262 | 27 | return $tb->ok(_include_in_headers($response->headers_to_array, $expected), $test_name); | |||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||
| 265 | sub response_redirect_location_is { | ||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my ($req, $expected, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_redirect_location_is: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | $test_name ||= "redirect location looks good for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$test_name ||= 'redirect location looks good for ' . _req_label($req)
MC/DC0%0/1
$test_name ||= 'redirect location looks good for ' . _req_label($req)
$test_name
Truth table0%0/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 271 | 0 | return $tb->is_eq($response->header('location'), $expected, $test_name); | |||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||
| 274 | sub response_redirect_location_like { | ||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | my ($req, $matcher, $test_name) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
response_redirect_location_like: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | $test_name ||= "redirect location looks good for " . _req_label($req); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$test_name ||= 'redirect location looks good for ' . _req_label($req)
MC/DC0%0/1
$test_name ||= 'redirect location looks good for ' . _req_label($req)
$test_name
Truth table0%0/2
A
A= $test_name
| |||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $tb = Test::Builder->new; | |||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $response = _req_to_response($req); | |||||||||||||||||||||||||||||||||||
| 280 | 0 | return $tb->like($response->header('location'), $matcher, $test_name); | |||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||
| 284 | # make sure the given header sublist is included in the full headers array | ||||||||||||||||||||||||||||||||||||
| 285 | sub _include_in_headers { | ||||||||||||||||||||||||||||||||||||
| 286 | 27 | ▶ | my ($full_headers, $expected_subset) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_include_in_headers: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||
| 288 | # walk through all the expected header pairs, make sure | ||||||||||||||||||||||||||||||||||||
| 289 | # they exist with the same value in the full_headers list | ||||||||||||||||||||||||||||||||||||
| 290 | # return false as soon as one is not. | ||||||||||||||||||||||||||||||||||||
| 291 | 27 | ▶ | for (my $i=0; $i<scalar(@$expected_subset); $i+=2) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 292 | 45 | my ($name, $value) = ($expected_subset->[$i], $expected_subset->[$i + 1]); | |||||||||||||||||||||||||||||||||||
| 293 | 45 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 294 | unless _check_header($full_headers, $name, $value); | ||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||
| 297 | # we've found all the expected pairs in the $full_headers list | ||||||||||||||||||||||||||||||||||||
| 298 | 27 | return 1; | |||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||
| 301 | sub _check_header { | ||||||||||||||||||||||||||||||||||||
| 302 | 45 | ▶ | my ($headers, $key, $value) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_check_header: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||
| 303 | 45 | ▶ | for (my $i=0; $i<scalar(@$headers); $i+=2) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 304 | 112 | my ($name, $val) = ($headers->[$i], $headers->[$i + 1]); | |||||||||||||||||||||||||||||||||||
| 305 | 112 | ▶ | return 1 if $name eq $key && $value eq $val; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name eq $key and $value eq $val
MC/DC100%2/2
$name eq $key and $value eq $val
$name eq $key
$value eq $val
Truth table100%3/3
A and B
A= $name eq $keyB= $value eq $val
| |||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||
| 307 | 0 | return 0; | |||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||
| 310 | sub dancer_response { | ||||||||||||||||||||||||||||||||||||
| 311 | 499 | ▶ | my ($method, $path, $args) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
dancer_response: called CC=34 SCAR=35.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 312 | 499 | ▶ | $args ||= {}; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= {}
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||
| 313 | 499 | my $extra_env = {}; | |||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||
| 315 | 499 | ▶ | if ($method =~ /^(?:PUT|POST)$/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||
| 317 | 28 | my ($content, $content_type); | |||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||
| 319 | 28 | ▶ | if ( $args->{body} and $args->{files} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$args->{"body"} and $args->{"files"}
MC/DC0%0/2
$args->{"body"} and $args->{"files"}
$args->{"body"}
$args->{"files"}
Truth table66%2/3
A and B
A= $args->{"body"}B= $args->{"files"}
| |||||||||||||||||||||||||||||||||||||
| 320 | # XXX: When fixing this, update this method's POD | ||||||||||||||||||||||||||||||||||||
| 321 | 0 | croak 'dancer_response() does not support both body and files'; | |||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||
| 323 | elsif ( $args->{body} ) { | ||||||||||||||||||||||||||||||||||||
| 324 | 13 | $content = $args->{body}; | |||||||||||||||||||||||||||||||||||
| 325 | $content_type = $args->{content_type} | ||||||||||||||||||||||||||||||||||||
| 326 | 13 | ▶ | || 'text/plain'; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'content_type'} || 'text/plain'
MC/DC100%1/1
$args->{'content_type'} || 'text/plain'
$args->{'content_type'}
Truth table100%2/2
A
A= $args->{'content_type'}
| |||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||
| 328 | # coerce hashref into an url-encoded string | ||||||||||||||||||||||||||||||||||||
| 329 | 13 | ▶ | if ( ref($content) && ( ref($content) eq 'HASH' ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $content and ref $content eq "HASH"
MC/DC50%1/2
ref $content and ref $content eq "HASH"
ref $content
ref $content eq "HASH"
Truth table66%2/3
A and B
A= ref $contentB= ref $content eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 330 | 3 | my @tokens; | |||||||||||||||||||||||||||||||||||
| 331 | 3 | ▶ | while ( my ( $name, $value ) = each %{$content} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 332 | 3 | $name = _url_encode($name); | |||||||||||||||||||||||||||||||||||
| 333 | 3 | ▶ | my @values = ref $value eq 'ARRAY' ? @$value : ($value); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 334 | 3 | for my $value (@values) { | |||||||||||||||||||||||||||||||||||
| 335 | 4 | $value = _url_encode($value); | |||||||||||||||||||||||||||||||||||
| 336 | 4 | push @tokens, "${name}=${value}"; | |||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||
| 339 | 3 | $content = join( '&', @tokens ); | |||||||||||||||||||||||||||||||||||
| 340 | 3 | $content_type = 'application/x-www-form-urlencoded'; | |||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||
| 343 | elsif ( $args->{files} ) { | ||||||||||||||||||||||||||||||||||||
| 344 | 3 | $content_type = 'multipart/form-data; boundary=----BOUNDARY'; | |||||||||||||||||||||||||||||||||||
| 345 | 3 | foreach my $file (@{$args->{files}}){ | |||||||||||||||||||||||||||||||||||
| 346 | 5 | ▶ | $file->{content_type} ||= 'text/plain'; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$file->{"content_type"} ||= "text/plain"
MC/DC0%0/1
$file->{"content_type"} ||= "text/plain"
$file->{"content_type"}
Truth table50%1/2
A
A= $file->{"content_type"}
| |||||||||||||||||||||||||||||||||||||
| 347 | 5 | $content .= qq/------BOUNDARY\r\n/; | |||||||||||||||||||||||||||||||||||
| 348 | 5 | $content .= qq/Content-Disposition: form-data; name="$file->{name}"; filename="$file->{filename}"\r\n/; | |||||||||||||||||||||||||||||||||||
| 349 | 5 | $content .= qq/Content-Type: $file->{content_type}\r\n\r\n/; | |||||||||||||||||||||||||||||||||||
| 350 | 5 | ▶ | if ( $file->{data} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 351 | 1 | $content .= $file->{data}; | |||||||||||||||||||||||||||||||||||
| 352 | } else { | ||||||||||||||||||||||||||||||||||||
| 353 | open my $fh, '<', $file->{filename} | ||||||||||||||||||||||||||||||||||||
| 354 | 4 | ▶ | or die "Failed to open $file->{filename} - $!"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 355 | 4 | ▶ | if ( -B $file->{filename} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 356 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||
| 358 | 4 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 359 | 4 | $content .= $_; | |||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||
| 362 | 5 | $content .= "\r\n"; | |||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||
| 364 | 3 | $content .= "------BOUNDARY"; | |||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||
| 367 | 28 | my $l = 0; | |||||||||||||||||||||||||||||||||||
| 368 | 28 | ▶ | $l = length $content if defined $content; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 369 | 28 | open my $in, '<', \$content; | |||||||||||||||||||||||||||||||||||
| 370 | 28 | $extra_env->{'CONTENT_LENGTH'} = $l; | |||||||||||||||||||||||||||||||||||
| 371 | 28 | ▶ | $extra_env->{'CONTENT_TYPE'} = $content_type || ""; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$content_type || ''
MC/DC100%1/1
$content_type || ''
$content_type
Truth table100%2/2
A
A= $content_type
| |||||||||||||||||||||||||||||||||||||
| 372 | 28 | $extra_env->{'psgi.input'} = $in; | |||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||
| 375 | 499 | my ($params, $body, $headers) = @$args{qw(params body headers)}; | |||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||
| 377 | 499 | ▶ | $headers = HTTP::Headers->new(@{$headers||[]}) | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 378 | unless _isa($headers, "HTTP::Headers"); | ||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||
| 380 | 499 | ▶ | if ($headers->header('Content-Type')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 381 | 16 | $extra_env->{'CONTENT_TYPE'} = $headers->header('Content-Type'); | |||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||
| 384 | # handle all the keys of Request::_build_request_env(): | ||||||||||||||||||||||||||||||||||||
| 385 | 499 | for my $key (qw( user_agent host accept_language accept_charset | |||||||||||||||||||||||||||||||||||
| 386 | accept_encoding keep_alive connection accept accept_type referer | ||||||||||||||||||||||||||||||||||||
| 387 | x_requested_with )) { | ||||||||||||||||||||||||||||||||||||
| 388 | 5489 | my $k = sprintf("HTTP_%s", uc $key); | |||||||||||||||||||||||||||||||||||
| 389 | $extra_env->{$k} = $headers->{$key} | ||||||||||||||||||||||||||||||||||||
| 390 | 5489 | ▶ | if exists $headers->{$key}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||
| 393 | # fake the REQUEST_URI | ||||||||||||||||||||||||||||||||||||
| 394 | # TODO deal with the params | ||||||||||||||||||||||||||||||||||||
| 395 | 499 | ▶ | unless( $extra_env->{REQUEST_URI} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 396 | 499 | $extra_env->{REQUEST_URI} = $path; | |||||||||||||||||||||||||||||||||||
| 397 | 499 | ▶ | if ( $method eq 'GET' and $params ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$method eq "GET" and $params
MC/DC100%2/2
$method eq "GET" and $params
$method eq "GET"
$params
Truth table100%3/3
A and B
A= $method eq "GET"B= $params
| |||||||||||||||||||||||||||||||||||||
| 398 | $extra_env->{REQUEST_URI} .= | ||||||||||||||||||||||||||||||||||||
| 399 | 8 | '?' . join '&', map { join '=', $_, $params->{$_} } | |||||||||||||||||||||||||||||||||||
| 400 | sort keys %$params; | ||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||
| 404 | 499 | my $request = Dancer::Request->new_for_request( | |||||||||||||||||||||||||||||||||||
| 405 | $method => $path, | ||||||||||||||||||||||||||||||||||||
| 406 | $params, $body, $headers, $extra_env | ||||||||||||||||||||||||||||||||||||
| 407 | ); | ||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||
| 409 | # first, reset the current state | ||||||||||||||||||||||||||||||||||||
| 410 | 499 | Dancer::SharedData->reset_all(); | |||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||
| 412 | # then store the request | ||||||||||||||||||||||||||||||||||||
| 413 | 499 | Dancer::SharedData->request($request); | |||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||
| 415 | # XXX this is a hack!! | ||||||||||||||||||||||||||||||||||||
| 416 | 499 | ▶ | $request = Dancer::Serializer->process_request($request) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 417 | if Dancer::App->current->setting('serializer'); | ||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||
| 419 | 499 | my $get_action = Dancer::Handler::render_request($request); | |||||||||||||||||||||||||||||||||||
| 420 | 499 | my $response = Dancer::SharedData->response(); | |||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||
| 422 | 499 | ▶ | $response->content('') if $method eq 'HEAD'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 423 | 499 | Dancer::SharedData->reset_response(); | |||||||||||||||||||||||||||||||||||
| 424 | 499 | ▶ | return $response if $get_action; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | (defined $response && $response->exists) ? return $response : return undef; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $response and $response->exists
MC/DC0%0/2
defined $response and $response->exists
defined $response
$response->exists
Truth table0%0/3
A and B
A= defined $responseB= $response->exists
| |||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||
| 428 | # private | ||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||
| 430 | sub _url_encode { | ||||||||||||||||||||||||||||||||||||
| 431 | 7 | ▶ | my $string = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_url_encode: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 432 | 7 | $string =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg; | |||||||||||||||||||||||||||||||||||
| 433 | 7 | return $string; | |||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||
| 436 | sub _get_file_response { | ||||||||||||||||||||||||||||||||||||
| 437 | 7 | ▶ | my ($req) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_file_response: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||
| 439 | 7 | my ($method, $path, $params) = expand_req($req); | |||||||||||||||||||||||||||||||||||
| 440 | 7 | my $request = Dancer::Request->new_for_request($method => $path, $params); | |||||||||||||||||||||||||||||||||||
| 441 | 7 | Dancer::SharedData->request($request); | |||||||||||||||||||||||||||||||||||
| 442 | 7 | return Dancer::Renderer::get_file_response(); | |||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||
| 445 | sub _get_handler_response { | ||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | my ($req) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_handler_response: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 447 | 0 | my ($method, $path, $params) = expand_req($req); | |||||||||||||||||||||||||||||||||||
| 448 | 0 | my $request = Dancer::Request->new_for_request($method => $path, $params); | |||||||||||||||||||||||||||||||||||
| 449 | 0 | return Dancer::Handler->handle_request($request); | |||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||
| 452 | sub read_logs { | ||||||||||||||||||||||||||||||||||||
| 453 | 2 | ▶ | return Dancer::Logger::Capture->trap->read; | ||||||||||||||||||||||||||||||||||
|
Subroutine
read_logs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||
| 457 | 86 | 1; | |||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||
| 459 | __END__ | ||||||||||||||||||||||||||||||||||||