[Catalyst-commits] r14554 - in Catalyst-Plugin-Compress/trunk: . lib/Catalyst/Plugin t
jnapiorkowski at dev.catalyst.perl.org
jnapiorkowski at dev.catalyst.perl.org
Mon Dec 29 16:13:06 GMT 2014
Author: jnapiorkowski
Date: 2014-12-29 16:13:06 +0000 (Mon, 29 Dec 2014)
New Revision: 14554
Added:
Catalyst-Plugin-Compress/trunk/Changes
Catalyst-Plugin-Compress/trunk/t/utf8.t
Modified:
Catalyst-Plugin-Compress/trunk/Makefile.PL
Catalyst-Plugin-Compress/trunk/lib/Catalyst/Plugin/Compress.pm
Log:
updated to work with new catalyst
Added: Catalyst-Plugin-Compress/trunk/Changes
===================================================================
--- Catalyst-Plugin-Compress/trunk/Changes (rev 0)
+++ Catalyst-Plugin-Compress/trunk/Changes 2014-12-29 16:13:06 UTC (rev 14554)
@@ -0,0 +1,5 @@
+# This file documents the revision history for Perl extension Catalyst::Plugin::Compress.
+
+0.006 - 2014-12-29
+ - Updated to support the upcoming release of Catalyst v5.90080. Added
+ test case and new documentation.
Modified: Catalyst-Plugin-Compress/trunk/Makefile.PL
===================================================================
--- Catalyst-Plugin-Compress/trunk/Makefile.PL 2014-12-20 00:47:28 UTC (rev 14553)
+++ Catalyst-Plugin-Compress/trunk/Makefile.PL 2014-12-29 16:13:06 UTC (rev 14554)
@@ -9,6 +9,7 @@
recommends 'Compress::Bzip2' => 2;
requires 'MRO::Compat';
requires 'Catalyst::Runtime' => '5.80001';
+test_requires 'HTTP::Request::Common';
auto_install;
resources repository => 'http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Plugin-Compress/trunk/';
Modified: Catalyst-Plugin-Compress/trunk/lib/Catalyst/Plugin/Compress.pm
===================================================================
--- Catalyst-Plugin-Compress/trunk/lib/Catalyst/Plugin/Compress.pm 2014-12-20 00:47:28 UTC (rev 14553)
+++ Catalyst-Plugin-Compress/trunk/lib/Catalyst/Plugin/Compress.pm 2014-12-29 16:13:06 UTC (rev 14554)
@@ -4,7 +4,7 @@
use Catalyst::Utils;
use MRO::Compat;
-our $VERSION = '0.005';
+our $VERSION = '0.006';
my $_method;
my %_compression_lib = (
@@ -102,6 +102,11 @@
return $c->maybe::next::method(@_);
}
+ # Hack to support newer Catalyst. We need to invokce the encoding stuff
+ # Now since after the content encoding header is set, we can no longer
+ # call that method. (jnap, to support 590080+)
+ $c->finalize_encoding if($c->can('encoding') and $c->can('clear_encoding'));
+
my $body = $c->res->body;
if (ref $body) {
eval { local $/; $body = <$body> };
@@ -130,15 +135,21 @@
use Catalyst qw/Compress/;
-or
+or (Catalyst pre Unicode Merge, and If you want to use this plugin with
+L<Catalyst::Plugin::Unicode>.)
use Catalyst qw/
Unicode
Compress
/;
-If you want to use this plugin with L<Catalyst::Plugin::Unicode>.
+or (Catalyst 5.90080 and later)
+ use Catalyst qw/
+ Compress
+ /;
+
+
Remember to specify compression_format with:
__PACKAGE__->config(
@@ -153,9 +164,12 @@
This module combines L<Catalyst::Plugin::Deflate> L<Catalyst::Plugin::Gzip>
L<Catalyst::Plugin::Zlib> into one.
-It compress response to [gzip bzip2 zlib deflate] if client supports it.
+It compress response to [gzip bzip2 zlib deflate] if client supports it. In other
+works the client should send the Accept-Encoding HTTP header with a supported
+compression like 'gzip'.
-B<NOTE>: If you want to use this module with L<Catalyst::Plugin::Unicode>, You
+B<NOTE>: If you are using an older version of L<Catalyst> that requires the Unicode
+plugin and if you want to use this module with L<Catalyst::Plugin::Unicode>, You
B<MUST> load this plugin B<AFTER> L<Catalyst::Plugin::Unicode>.
use Catalyst qw/
@@ -168,6 +182,9 @@
[error] Caught exception in engine "Wide character in subroutine entry at
/usr/lib/perl5/site_perl/5.8.8/Compress/Zlib.pm line xxx."
+If you upgrade to any version of L<Catalyst> 5.90080+ the unicode support has been
+integrated into core code and this plugin is designed to work with that.
+
=head1 INTERNAL METHODS
=head2 should_compress_response
Added: Catalyst-Plugin-Compress/trunk/t/utf8.t
===================================================================
--- Catalyst-Plugin-Compress/trunk/t/utf8.t (rev 0)
+++ Catalyst-Plugin-Compress/trunk/t/utf8.t 2014-12-29 16:13:06 UTC (rev 14554)
@@ -0,0 +1,43 @@
+use utf8;
+use warnings;
+use strict;
+use Test::More;
+use Encode 2.21 'decode_utf8', 'encode_utf8';
+use HTTP::Request::Common;
+use Compress::Zlib;
+
+{
+ package MyApp::Controller::Root;
+ $INC{'MyApp/Controller/Root.pm'} = __FILE__;
+
+ use base 'Catalyst::Controller';
+
+ sub heart :Path('♥') {
+ my ($self, $c) = @_;
+ $c->response->content_type('text/html');
+ $c->response->body("<p>This is path-heart action ♥</p>");
+ }
+
+ package MyApp;
+ use Catalyst 'Compress';
+
+ MyApp->config(compression_format => 'gzip');
+ MyApp->setup;
+}
+
+use Catalyst::Test 'MyApp';
+
+if(MyApp->can('encoding') and MyApp->can('clear_encoding') ) {
+ ok my $res = request GET '/root/♥', 'Accept-Encoding' => 'gzip';
+
+ is $res->code, 200, 'OK';
+ ok my $gunzip = Compress::Zlib::memGunzip($res->content);
+
+ is decode_utf8($gunzip), "<p>This is path-heart action ♥</p>", 'correct body';
+ is $res->content_charset, 'UTF-8';
+} else {
+ ok 1, 'Skipping the UTF8 Tests for older installed catalyst';
+}
+
+done_testing;
+
More information about the Catalyst-commits
mailing list