| 1 | package Catalyst::Plugin::Compress::WithExclusions; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use base qw(Catalyst::Plugin::Compress); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | Catalyst::Plugin::Compress::WithExclusions - Compresses all responses from the server, except excluded paths | ||||||||||
| 10 | |||||||||||
| 11 | =head1 VERSION | ||||||||||
| 12 | |||||||||||
| 13 | Version 0.02 | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | 2 | our $VERSION = '0.02'; | |||||||||
| 18 | |||||||||||
| 19 | 2 | my @excluded = (); | |||||||||
| 20 | |||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||
| 22 | |||||||||||
| 23 | use Catalyst qw/Compress::WithExclusions/; | ||||||||||
| 24 | |||||||||||
| 25 | Then specifiy the excluded paths as an array ref of regular expressions | ||||||||||
| 26 | and the compression format that you want to use. | ||||||||||
| 27 | |||||||||||
| 28 | __PACKAGE__->config( | ||||||||||
| 29 | compression_excluded => ['path_regex', ], | ||||||||||
| 30 | compression_format => $format | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | Accepted formats for $format are the same as defined in L<Catalyst::Plugin::Compress> | ||||||||||
| 34 | |||||||||||
| 35 | =head1 DESCRIPTION | ||||||||||
| 36 | |||||||||||
| 37 | It is always a good idea to compress the results that are returned from | ||||||||||
| 38 | your web application, if the client can handle it. L<Catalyst::Plugin::Compress> | ||||||||||
| 39 | does that for you with very little effort. However, there are times when you might | ||||||||||
| 40 | not want the reponse to be compressed. For example when a returning a file that has | ||||||||||
| 41 | already been zipped. The extra compression is unlikely to reduce the file size and | ||||||||||
| 42 | will just add extra load to the server. This module builds upon the | ||||||||||
| 43 | L<Catalyst::Plugin::Compress> module and adds the option to skip the compression step | ||||||||||
| 44 | for certain url paths. So, for example, if you dont want to compress any files in the | ||||||||||
| 45 | download path, then you would add the following to your config: | ||||||||||
| 46 | |||||||||||
| 47 | __PACKAGE__->config( | ||||||||||
| 48 | compression_excluded => ['^download', ], | ||||||||||
| 49 | ); | ||||||||||
| 50 | |||||||||||
| 51 | Now all urls on the site that start with download will be uncompressed and everything | ||||||||||
| 52 | else will be compressed as requested. | ||||||||||
| 53 | |||||||||||
| 54 | =head1 SUBROUTINES/METHODS | ||||||||||
| 55 | |||||||||||
| 56 | =head2 setup | ||||||||||
| 57 | |||||||||||
| 58 | This is an internal method. It checks to see if any exclusions have been | ||||||||||
| 59 | added in the configuration file. | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub setup { | ||||||||
|
Subroutine
setup: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 64 | 0 | my $c = shift; | |||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | if (exists $c->config->{compression_excluded}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | ▶ | if (ref($c->config->{compression_excluded}) eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | @excluded = @{$c->config->{compression_excluded}}; | |||||||||
| 69 | } | ||||||||||
| 70 | else { | ||||||||||
| 71 | 0 | ▶ | if ($c->debug) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | $c->log->debug("'compression_excluded' configuration should be an array reference'"); | |||||||||
| 73 | } | ||||||||||
| 74 | } | ||||||||||
| 75 | } | ||||||||||
| 76 | 0 | $c->maybe::next::method(@_); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | =head2 should_compress_response | ||||||||||
| 80 | |||||||||||
| 81 | This is an internal method that first checks to see if the path should be excluded | ||||||||||
| 82 | from compression and then passes on to the parent for further checks. | ||||||||||
| 83 | |||||||||||
| 84 | =cut | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub should_compress_response { | ||||||||
|
Subroutine
should_compress_response: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 87 | 0 | my $c = shift; | |||||||||
| 88 | 0 | my $action = $c->req->action; | |||||||||
| 89 | |||||||||||
| 90 | 0 | foreach my $test (@excluded) { | |||||||||
| 91 | 0 | ▶ | if ($action =~ /$test/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | return; | |||||||||
| 93 | } | ||||||||||
| 94 | } | ||||||||||
| 95 | 0 | $c->maybe::next::method(@_); | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | =head1 AUTHOR | ||||||||||
| 99 | |||||||||||
| 100 | Jody Clements, C<< <clementsj at janelia.hhmi.org> >> | ||||||||||
| 101 | |||||||||||
| 102 | =head1 BUGS | ||||||||||
| 103 | |||||||||||
| 104 | Please report any bugs or feature requests to C<bug-catalyst-plugin-compress-hmmer at rt.cpan.org>, or through | ||||||||||
| 105 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-Compress-WithExclusions>. I will be notified, and then you'll | ||||||||||
| 106 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 107 | |||||||||||
| 108 | |||||||||||
| 109 | =head1 SUPPORT | ||||||||||
| 110 | |||||||||||
| 111 | You can find documentation for this module with the perldoc command. | ||||||||||
| 112 | |||||||||||
| 113 | perldoc Catalyst::Plugin::Compress::WithExclusions | ||||||||||
| 114 | |||||||||||
| 115 | |||||||||||
| 116 | You can also look for information at: | ||||||||||
| 117 | |||||||||||
| 118 | =over 4 | ||||||||||
| 119 | |||||||||||
| 120 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||
| 121 | |||||||||||
| 122 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Compress-WithExclusions> | ||||||||||
| 123 | |||||||||||
| 124 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 125 | |||||||||||
| 126 | L<http://annocpan.org/dist/Catalyst-Plugin-Compress-WithExclusions> | ||||||||||
| 127 | |||||||||||
| 128 | =item * CPAN Ratings | ||||||||||
| 129 | |||||||||||
| 130 | L<http://cpanratings.perl.org/d/Catalyst-Plugin-Compress-WithExclusions> | ||||||||||
| 131 | |||||||||||
| 132 | =item * Search CPAN | ||||||||||
| 133 | |||||||||||
| 134 | L<http://search.cpan.org/dist/Catalyst-Plugin-Compress-WithExclusions/> | ||||||||||
| 135 | |||||||||||
| 136 | =back | ||||||||||
| 137 | |||||||||||
| 138 | |||||||||||
| 139 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 140 | |||||||||||
| 141 | |||||||||||
| 142 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 143 | |||||||||||
| 144 | Copyright 2012 Jody Clements. | ||||||||||
| 145 | |||||||||||
| 146 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 147 | under the terms of either: the GNU General Public License as published | ||||||||||
| 148 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 149 | |||||||||||
| 150 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 151 | |||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||
| 154 | |||||||||||
| 155 | 2 | 1; # End of Catalyst::Plugin::Compress::WithExclusions | |||||||||