File Coverage

blib/lib/Plack/Middleware/REST/Util.pm
Criterion Covered Total %
statement 14 14 100.0
branch 3 6 50.0
condition 1 2 50.0
subroutine 5 5 100.0
pod 0 3 0.0
total 23 30 76.6


line stmt bran cond sub pod time code
1             package Plack::Middleware::REST::Util;
2              
3             our $VERSION = '0.03';
4              
5 1     1   73734 use Plack::Request;
  1         2  
  1         22  
6              
7 1     1   4 use parent 'Exporter';
  1         6  
  1         5  
8              
9             our @EXPORT = qw(request_id request_content request_uri);
10              
11             sub request_id {
12 12   50 12 0 1524 substr($_[0]->{PATH_INFO} || '/',1)
13             }
14              
15             sub request_content {
16 4 50   4 0 31 return unless defined $_[0]->{CONTENT_LENGTH};
17 4         26 return (Plack::Request->new($_[0])->content => $_[0]->{CONTENT_TYPE});
18             }
19              
20             sub request_uri {
21 4     4 0 1651 my $env = shift;
22 4 50       11 my $id = @_ ? shift : request_id($env);
23 4         12 my $uri = Plack::Request->new($env)->base;
24 4 50       498 $uri .= '/' unless $uri =~ qr{/$};
25 4         38 return $uri . $id;
26             }
27              
28             1;
29             __END__