File Coverage

blib/lib/Plack/Middleware/TimeOverHTTP.pm
Criterion Covered Total %
statement 22 23 95.6
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             package Plack::Middleware::TimeOverHTTP;
2              
3             # ABSTRACT: time over HTTP middleware
4              
5 1     1   671 use v5.8.5;
  1         4  
6              
7 1     1   5 use strict;
  1         2  
  1         20  
8 1     1   5 use warnings;
  1         2  
  1         26  
9              
10 1     1   5 use parent 'Plack::Middleware';
  1         3  
  1         6  
11              
12 1     1   67 use HTTP::Status qw/ :constants /;
  1         2  
  1         451  
13 1     1   559 use Time::HiRes 1.9764 qw/ clock_gettime CLOCK_REALTIME /;
  1         1306  
  1         5  
14              
15             our $VERSION = 'v0.1.2';
16              
17             sub call {
18 2     2 1 25145 my ( $self, $env ) = @_;
19              
20 2 50       9 unless ( $env->{REQUEST_URI} eq '/.well-known/time' ) {
21 0         0 return $self->app->($env);
22             }
23              
24 2 100       6 unless ( $env->{REQUEST_METHOD} eq 'HEAD' ) {
25 1         11 return [ HTTP_METHOD_NOT_ALLOWED, [], [] ];
26             }
27              
28             [
29 1         7 HTTP_NO_CONTENT,
30             [
31             'X-HTTPSTIME' => clock_gettime(CLOCK_REALTIME),
32             ],
33             [],
34             ];
35              
36             }
37              
38             1;
39              
40             __END__