blib/lib/Catalyst/ActionRole/CheckTrailingSlash.pm

filter: Statementstmt 50.0% 9 / 18 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod n/a totaltotal 47.8% 11 / 23 CC 2 SCAR 12.5
CC
2
Cov
45%
__ANON__
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
↑ Summary
1 package Catalyst::ActionRole::CheckTrailingSlash;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 1 our $VERSION = '0.01';
8  
9  
10 0 ▶around execute => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
11 0 my $orig = shift;
12 0 my $self = shift;
13 0 my ($controller, $c) = @_;
14 0 my $uri = $c->req->uri;
15  
16 0 ▶ if ( $uri->path !~ m{/$} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($uri->path =~ m[/$]) 0 0 0
17 {
18 0 $uri->path( $uri->path.'/' );
19 0 $c->res->redirect( $uri, 301 );
20 0 return;
21 }
22 0 $self->$orig( @_ );
23 1 };
24  
25 1 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
↑ Summary