File Coverage

blib/lib/Dancer2/Core/Response/Delayed.pm
Criterion Covered Total %
statement 15 15 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 22 22 100.0


line stmt bran cond sub pod time code
1             package Dancer2::Core::Response::Delayed;
2             # ABSTRACT: Delayed responses
3             $Dancer2::Core::Response::Delayed::VERSION = '2.0.1';
4 144     144   633501 use Moo;
  144         10477  
  144         973  
5 144     144   64942 use Dancer2::Core::Types qw;
  144         559  
  144         1695  
6              
7             has request => (
8             is => 'ro',
9             isa => InstanceOf['Dancer2::Core::Request'],
10             required => 1,
11             );
12              
13             has response => (
14             is => 'ro',
15             isa => InstanceOf['Dancer2::Core::Response'],
16             required => 1,
17             handles => [qw/status headers push_header/],
18             );
19              
20             has cb => (
21             is => 'ro',
22             isa => CodeRef,
23             required => 1,
24             );
25              
26             has error_cb => (
27             is => 'ro',
28             isa => CodeRef,
29             predicate => '_has_error_cb',
30             );
31              
32             sub is_halted() {0}
33             sub has_passed() {0}
34              
35             sub to_psgi {
36 20     20 1 5586 my $self = shift;
37              
38             return sub {
39 20     20   3244 my $responder = shift;
40              
41 20         91 local $Dancer2::Core::Route::REQUEST = $self->request;
42 20         75 local $Dancer2::Core::Route::RESPONSE = $self->response;
43 20         50 local $Dancer2::Core::Route::RESPONDER = $responder;
44 20         95 local $Dancer2::Core::Route::WRITER;
45              
46 20 100       126 local $Dancer2::Core::Route::ERROR_HANDLER =
47             $self->_has_error_cb ? $self->error_cb : undef;
48              
49 20         132 $self->cb->();
50 20         180 };
51             }
52              
53             1;
54              
55             __END__