[Jifty-commit] jifty branch, plack-rebased, updated. 686bc526ace9c0c23cf125aabb69e9eea0478ffa
Jifty commits
jifty-commit at lists.jifty.org
Sun Feb 7 04:41:12 EST 2010
The branch, plack-rebased has been updated
via 686bc526ace9c0c23cf125aabb69e9eea0478ffa (commit)
via cda337155d8a94fb3a4f72a1a60a009c91d52c02 (commit)
via 05d7b3aac94213a471be4ff796a4f478bbe9b2dd (commit)
from dae6c2f4d2c4ebd6e786e55b465c92e9cf32754f (commit)
Summary of changes:
Changelog | 2 +-
Makefile.PL | 1 +
lib/Jifty/Handler.pm | 21 ++++--------------
lib/Jifty/Plugin.pm | 13 +++++++++++
lib/Jifty/Plugin/Compat.pm | 19 ++++++++++++++--
lib/Jifty/Plugin/Deflater.pm | 47 +++++++++++++++++++++++++++++++++++++++++
t/TestApp/lib/TestApp/View.pm | 2 +-
t/TestApp/t/99deprecation.t | 2 +-
t/TestApp/t/config-Cachable | 4 +++
9 files changed, 89 insertions(+), 22 deletions(-)
create mode 100644 lib/Jifty/Plugin/Deflater.pm
- Log -----------------------------------------------------------------
commit 05d7b3aac94213a471be4ff796a4f478bbe9b2dd
Author: Chia-liang Kao <clkao at clkao.org>
Date: Sun Feb 7 17:19:20 2010 +0800
Allow plugins to wrap psgi-app.
diff --git a/lib/Jifty/Handler.pm b/lib/Jifty/Handler.pm
index 2d3b7bc..c1f34b6 100644
--- a/lib/Jifty/Handler.pm
+++ b/lib/Jifty/Handler.pm
@@ -126,7 +126,11 @@ sub psgi_app {
my $app = sub { $self->handle_request(@_) };
# allow plugin to wrap $app
- builder {
+ for ( Jifty->plugins ) {
+ $app = $_->wrap($app);
+ }
+
+ $app = builder {
enable 'Deflater';
enable sub { my $app = shift;
sub { my $env = shift;
@@ -140,6 +144,8 @@ sub psgi_app {
};
$app;
};
+
+ return $app;
}
=head2 handle_request
diff --git a/lib/Jifty/Plugin.pm b/lib/Jifty/Plugin.pm
index a191067..2f85483 100644
--- a/lib/Jifty/Plugin.pm
+++ b/lib/Jifty/Plugin.pm
@@ -286,4 +286,17 @@ sub table_prefix {
return lc $class;
}
+=head2 wrap
+
+Takes a PSGI-$app closure and returns the wrapped one if your plugin
+wants to do something to the request handling process. See also
+L<Plack::Middleware>.
+
+=cut
+
+sub wrap {
+ my ($self, $app) = @_;
+ return $app;
+}
+
1;
commit cda337155d8a94fb3a4f72a1a60a009c91d52c02
Author: Chia-liang Kao <clkao at clkao.org>
Date: Sun Feb 7 17:21:52 2010 +0800
Provide %ENV in the compat plugin.
diff --git a/Changelog b/Changelog
index ecc1ee3..5bb964d 100644
--- a/Changelog
+++ b/Changelog
@@ -16,7 +16,7 @@ INCOMPATABILITIES
* Printing to STDOUT deprecated. Use outs, outs_raw, or
Jifty->web->response->body() instead.
- * munging with the %ENV hash is no longer supported. Use
+ * munging with the %ENV hash is deprecated. Use
Jifty->web->request->env instead.
-----------------------------------
diff --git a/Makefile.PL b/Makefile.PL
index 5ecb500..f4d5b9b 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -14,6 +14,7 @@ requires('Class::Trigger' => '0.13');
requires('Clone' => '0.27');
requires('CGI' => '3.30');
requires('CGI::Cookie::Splitter');
+requires('CGI::Emulate::PSGI');
requires('Class::Inspector' => 1.20); # For File::ShareDir on Win32
requires('Crypt::CBC');
requires('Crypt::Rijndael');
diff --git a/lib/Jifty/Plugin/Compat.pm b/lib/Jifty/Plugin/Compat.pm
index e449d52..dc67041 100644
--- a/lib/Jifty/Plugin/Compat.pm
+++ b/lib/Jifty/Plugin/Compat.pm
@@ -3,8 +3,8 @@ use warnings;
package Jifty::Plugin::Compat;
use base 'Jifty::Plugin';
-use Hook::LexWrap;
-require Jifty::View::Mason::Handler;
+use Hook::LexWrap ();
+use CGI::Emulate::PSGI ();
=head1 NAME
@@ -37,12 +37,25 @@ TODO: this should also rebind STDIN/STDOUT in the per-request hook.
return 'Jifty::Plugin::Compat::CGI';
};
-wrap 'Jifty::View::Mason::Handler::new',
+require Jifty::View::Mason::Handler;
+Hook::LexWrap::wrap 'Jifty::View::Mason::Handler::new',
post => sub { my $self = shift;
$self->interp->compiler->add_allowed_globals('$r');
$self->interp->set_global('$r', 'Jifty::Plugin::Compat::Apache');
};
+sub wrap {
+ my ($self, $app) = @_;
+
+ sub {
+ my $env = shift;
+ my %cgi = CGI::Emulate::PSGI->emulate_environment($env);
+ local *STDIN;
+ local %ENV = (%ENV, %cgi);
+ $app->($env);
+ }
+}
+
push @Jifty::TestServer::ISA, 'Jifty::Server';
package Jifty::Server;
diff --git a/t/TestApp/lib/TestApp/View.pm b/t/TestApp/lib/TestApp/View.pm
index 664dd0c..9c100c9 100644
--- a/t/TestApp/lib/TestApp/View.pm
+++ b/t/TestApp/lib/TestApp/View.pm
@@ -156,7 +156,7 @@ template 'otherplace' => page {
};
template 'naughty' => sub {
- print STDOUT "this is bad";
+ print STDOUT "this is bad: $ENV{REMOTE_HOST}";
};
1;
diff --git a/t/TestApp/t/99deprecation.t b/t/TestApp/t/99deprecation.t
index 2686453..e6d3ab2 100644
--- a/t/TestApp/t/99deprecation.t
+++ b/t/TestApp/t/99deprecation.t
@@ -11,6 +11,6 @@ my $URL = $server->started_ok;
my $mech = Jifty::Test::WWW::Mechanize->new();
my $request = HTTP::Request->new( GET => "$URL/naughty");
my $response = $mech->request($request);
-is($response->content, 'this is bad');
+is($response->content, 'this is bad: localhost');
$mech->warnings_like(qr/deprecated/);
commit 686bc526ace9c0c23cf125aabb69e9eea0478ffa
Author: Chia-liang Kao <clkao at clkao.org>
Date: Sun Feb 7 17:40:19 2010 +0800
Move Deflater to a separate plugin.
diff --git a/lib/Jifty/Handler.pm b/lib/Jifty/Handler.pm
index c1f34b6..08b14d6 100644
--- a/lib/Jifty/Handler.pm
+++ b/lib/Jifty/Handler.pm
@@ -28,8 +28,6 @@ use Jifty::View::Declare::Handler ();
use Class::Trigger;
use String::BufferStack;
use Plack::Request;
-use Plack::Builder;
-use Plack::Util;
__PACKAGE__->mk_accessors(qw(dispatcher _view_handlers stash buffer));
@@ -130,21 +128,6 @@ sub psgi_app {
$app = $_->wrap($app);
}
- $app = builder {
- enable 'Deflater';
- enable sub { my $app = shift;
- sub { my $env = shift;
- my $res = $app->($env);
- my $h = Plack::Util::headers($res->[1]);
- my $type = $h->get('Content-Type')
- or return $res;
- delete $env->{HTTP_ACCEPT_ENCODING}
- unless $type =~ m|application/x-javascript| || $type =~ m|^text/|;
- $res }
- };
- $app;
- };
-
return $app;
}
diff --git a/lib/Jifty/Plugin/Deflater.pm b/lib/Jifty/Plugin/Deflater.pm
new file mode 100644
index 0000000..19e6635
--- /dev/null
+++ b/lib/Jifty/Plugin/Deflater.pm
@@ -0,0 +1,47 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Deflater;
+use base 'Jifty::Plugin';
+use Plack::Builder;
+use Plack::Util;
+
+=head1 NAME
+
+Jifty::Plugin::Deflater - Handles Accept-Encoding and compression
+
+=head1 SYNOPSIS
+
+# In your jifty config.yml under the framework section:
+
+ Plugins:
+ - Deflater: {}
+
+# You should put defalter at the end of the plugins list
+
+=head1 DESCRIPTION
+
+This plugin provides Accept-Encoding handling.
+
+=cut
+
+sub wrap {
+ my ($self, $app) = @_;
+
+ builder {
+ enable 'Deflater';
+ enable sub { my $app = shift;
+ sub { my $env = shift;
+ my $res = $app->($env);
+ my $h = Plack::Util::headers($res->[1]);
+ my $type = $h->get('Content-Type')
+ or return $res;
+ delete $env->{HTTP_ACCEPT_ENCODING}
+ unless $type =~ m|application/x-javascript| || $type =~ m|^text/|;
+ $res }
+ };
+ $app;
+ };
+}
+
+1;
diff --git a/t/TestApp/t/config-Cachable b/t/TestApp/t/config-Cachable
index 0cb57c8..4be095a 100644
--- a/t/TestApp/t/config-Cachable
+++ b/t/TestApp/t/config-Cachable
@@ -2,3 +2,7 @@
framework:
Database:
RecordBaseClass: Jifty::DBI::Record::Cachable
+ Plugins:
+ - CompressedCSSandJS: {}
+ - SkeletonApp: {}
+ - Deflater: {}
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list