File Coverage

blib/lib/Plack/Middleware/ServerStatus/Tiny.pm
Criterion Covered Total %
statement 31 31 100.0
branch 5 6 83.3
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 46 47 97.8


line stmt bran cond sub pod time code
1 1     1   87004 use strict;
  1         3  
  1         39  
2 1     1   6 use warnings;
  1         2  
  1         75  
3             package Plack::Middleware::ServerStatus::Tiny;
4             {
5             $Plack::Middleware::ServerStatus::Tiny::VERSION = '0.002';
6             }
7             # git description: v0.001-4-geb5f2f5
8              
9             BEGIN {
10 1     1   20 $Plack::Middleware::ServerStatus::Tiny::AUTHORITY = 'cpan:ETHER';
11             }
12             # ABSTRACT: tiny middleware for providing server status information
13              
14 1     1   7 use parent 'Plack::Middleware';
  1         3  
  1         8  
15 1     1   27525 use Plack::Util::Accessor qw(path _uptime _access_count);
  1         6  
  1         16  
16 1     1   195 use Plack::Response;
  1         2  
  1         394  
17              
18             sub prepare_app
19             {
20 2     2 1 1374 my $self = shift;
21              
22 2 100       10 die 'missing required option: \'path\'' if not $self->path;
23 1 50       11 warn 'path "' . $self->path . '" does not begin with /, and will never match' if $self->path !~ m{^/};
24              
25 1         14 $self->_uptime(time);
26 1         66 $self->_access_count(0);
27             }
28              
29             sub call
30             {
31 4     4 1 40912 my ($self, $env) = @_;
32              
33 4         30 $self->_access_count($self->_access_count + 1);
34              
35 4 100       74 if ($env->{PATH_INFO} eq $self->path)
36             {
37 3         39 my $content = 'uptime: ' . (time - $self->_uptime)
38             . '; access count: ' . $self->_access_count;
39              
40 3         75 my $res = Plack::Response->new('200');
41 3         67 $res->content_type('text/plain');
42 3         96 $res->content_length(length $content);
43 3         105 $res->body($content);
44 3         27 return $res->finalize;
45             }
46              
47 1         23 $self->app->($env);
48             }
49              
50             1;
51              
52             __END__