File Coverage

blib/lib/Catalyst/ActionRole/CheckTrailingSlash.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Catalyst::ActionRole::CheckTrailingSlash;
2              
3 1     1   36464 use Moose::Role;
  1         595043  
  1         8  
4 1     1   7536 use namespace::autoclean;
  1         1687  
  1         7  
5              
6              
7             our $VERSION = '0.01';
8              
9              
10             around execute => sub {
11             my $orig = shift;
12             my $self = shift;
13             my ($controller, $c) = @_;
14             my $uri = $c->req->uri;
15              
16             if ( $uri->path !~ m{/$} )
17             {
18             $uri->path( $uri->path.'/' );
19             $c->res->redirect( $uri, 301 );
20             return;
21             }
22             $self->$orig( @_ );
23             };
24              
25             1;
26              
27             =head1 NAME
28              
29             Catalyst::ActionRole::CheckTrailingSlash - Test URI path for trailing slash and redirect if needed
30              
31             =cut
32              
33             =head1 SYNOPSIS
34              
35              
36             package MyApp::Controller::Root
37              
38             use Moose;
39             BEGIN { extends 'Catalyst::Controller::ActionRole' };
40              
41             sub info :Local :Does('CheckTrailingSlash')
42             {
43             my ( $self, $c ) = @_;
44             ...
45             }
46              
47             ...
48             =cut
49              
50             =head1 AUTHOR
51              
52             Anatoliy Lapitskiy, C<< <nuclon at cpan.org> >>
53              
54             =head1 BUGS
55              
56             Please report any bugs or feature requests to C<bug-catalyst-actionrole-checktrailingslash at rt.cpan.org>, or through
57             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-ActionRole-CheckTrailingSlash>. I will be notified, and then you'll
58             automatically be notified of progress on your bug as I make changes.
59              
60              
61              
62              
63             =head1 SUPPORT
64              
65             You can find documentation for this module with the perldoc command.
66              
67             perldoc Catalyst::ActionRole::CheckTrailingSlash
68              
69              
70             You can also look for information at:
71              
72             =over 4
73              
74             =item * RT: CPAN's request tracker
75              
76             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-ActionRole-CheckTrailingSlash>
77              
78             =item * AnnoCPAN: Annotated CPAN documentation
79              
80             L<http://annocpan.org/dist/Catalyst-ActionRole-CheckTrailingSlash>
81              
82             =item * CPAN Ratings
83              
84             L<http://cpanratings.perl.org/d/Catalyst-ActionRole-CheckTrailingSlash>
85              
86             =item * Search CPAN
87              
88             L<http://search.cpan.org/dist/Catalyst-ActionRole-CheckTrailingSlash/>
89              
90             =back
91              
92              
93             =head1 ACKNOWLEDGEMENTS
94              
95              
96             =head1 COPYRIGHT & LICENSE
97              
98             Copyright 2010 Anatoliy Lapitskiy.
99              
100             This program is free software; you can redistribute it and/or modify it
101             under the terms of either: the GNU General Public License as published
102             by the Free Software Foundation; or the Artistic License.
103              
104             See http://dev.perl.org/licenses/ for more information.
105              
106              
107             =cut