blib/lib/Bootylicious/Plugin/CanonicalUrl.pm untested

filter: Statementstmt 0.0% 0 / 21 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 34 CC 4 SCAR 24.0
CC
4
Cov
0%
_bridge
20.0
register
2.0
BEGIN
2.0
CRAP 11.0
1 package Bootylicious::Plugin::CanonicalUrl;
2  
3 use strict;
4 use warnings;
5  
6 use base 'Mojolicious::Plugin';
7  
8 sub register {
9 my ($self, $app, $conf) = @_;
10  
11 main::under(\&_bridge);
12 }
13  
14 sub _bridge {
15 my $self = shift;
16  
17 my $path = $self->req->url->path->to_string;
18 return 1 unless $path;
19  
20 return 1 if $path =~ m{/$};
21  
22 return 1 if $path =~ m{\.(?:[a-z]+)$};
23  
24 my $canonical_location =
25 $self->req->url->clone->path($path . '.html')->to_abs;
26  
27 $self->app->log->debug("Path is not canonical: " . $self->req->url);
28 $self->app->log->debug("Redirecting to: " . $canonical_location);
29  
30 $self->redirect_to($canonical_location);
31  
32 # Stop
33 return 0;
34 }
35  
36 1;