File Coverage

blib/lib/Dancer2/Plugin/RootURIFor.pm
Criterion Covered Total %
statement 19 20 95.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 27 29 93.1


line stmt bran cond sub pod time code
1 2     2   2921163 use strict;
  2         6  
  2         68  
2 2     2   12 use warnings;
  2         3  
  2         142  
3             package Dancer2::Plugin::RootURIFor;
4             {
5             $Dancer2::Plugin::RootURIFor::VERSION = '0.03';
6             }
7             # ABSTRACT: Mountpoint-agnostic uri builder for Dancer2
8              
9 2     2   1284 use URI::Escape;
  2         1512  
  2         172  
10 2     2   1761 use Dancer2::Plugin 0.15;
  2         112407  
  2         16  
11              
12             register root_uri_for => sub {
13 4     4   194590 my ( $dsl, $part, $params, $dont_escape ) = @_;
14 4         34 my $uri = $dsl->app->request->base;
15              
16 4         1049 $part =~ s{^/*}{/};
17 4         16 $uri->path("$part");
18              
19 4 100       109 $uri->query_form($params) if $params;
20              
21             return $dont_escape
22 0         0 ? uri_unescape( ${ $uri->canonical } )
23 4 50       110 : ${ $uri->canonical };
  4         12  
24             };
25              
26             register_plugin;
27              
28             1;
29              
30             __END__