[Catalyst-commits] r6442 - in trunk: .
Catalyst-Controller-WrapCGI/lib
Catalyst-Controller-WrapCGI/lib/CatalystX
Catalyst-Controller-WrapCGI/lib/CatalystX/Controller
examples/CatalystAdvent examples/CatalystAdvent/lib
examples/CatalystAdvent/lib/CatalystAdvent/Controller
jrockway at dev.catalyst.perl.org
jrockway at dev.catalyst.perl.org
Wed May 30 11:42:37 GMT 2007
Author: jrockway
Date: 2007-05-30 11:42:35 +0100 (Wed, 30 May 2007)
New Revision: 6442
Added:
trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/
trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/Controller/
trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/Controller/WrapCGI.pm
Modified:
trunk/
trunk/examples/CatalystAdvent/Makefile.PL
trunk/examples/CatalystAdvent/lib/CatalystAdvent.pm
trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
Log:
r26641 at foo: jon | 2007-05-30 05:03:19 -0500
add correct unicode awareness to CatalystAdvent
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 6d2a1d83-d666-409f-9dbf-d3bfcf4e9009:/local_branches/Catalyst-bad-mst/trunk:40156
6d2a1d83-d666-409f-9dbf-d3bfcf4e9009:/local_branches/Catalyst-broken-net/trunk:19004
6d2a1d83-d666-409f-9dbf-d3bfcf4e9009:/local_branches/Catalyst_acl_in_conf/trunk:3134
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst-trunk:26552
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/trunk:7830
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst/trunk:7023
+ 6d2a1d83-d666-409f-9dbf-d3bfcf4e9009:/local_branches/Catalyst-bad-mst/trunk:40156
6d2a1d83-d666-409f-9dbf-d3bfcf4e9009:/local_branches/Catalyst-broken-net/trunk:19004
6d2a1d83-d666-409f-9dbf-d3bfcf4e9009:/local_branches/Catalyst_acl_in_conf/trunk:3134
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst-trunk:26641
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/trunk:7830
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst/trunk:7023
Added: trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/Controller/WrapCGI.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/Controller/WrapCGI.pm (rev 0)
+++ trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/Controller/WrapCGI.pm 2007-05-30 10:42:35 UTC (rev 6442)
@@ -0,0 +1,99 @@
+package CatalystX::Controller::WrapCGI;
+
+# AUTHOR: Matt S Trout, mst at shadowcatsystems.co.uk
+# Original development sponsored by http://www.altinity.com/
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller';
+
+use HTTP::Request::AsCGI;
+use HTTP::Request;
+use URI::Escape;
+
+# Hack-around because Catalyst::Engine::HTTP goes and changes
+# them to be the remote socket, and FCGI.pm does even dumber things.
+
+open(*REAL_STDIN, "<&=".fileno(*STDIN));
+open(*REAL_STDOUT, ">>&=".fileno(*STDOUT));
+
+sub cgi_to_response {
+ my ($self, $c, $script) = @_;
+ my $res = $self->wrap_cgi($c, $script);
+
+ # if the CGI doesn't set the response code but sets location they were
+ # probably trying to redirect so set 302 for them
+
+ if (length($res->headers->header('Location')) && $res->code == 200) {
+ $c->res->status(302);
+ } else {
+ $c->res->status($res->code);
+ }
+ $c->res->body($res->content);
+ $c->res->headers($res->headers);
+}
+
+sub wrap_cgi {
+ my ($self, $c, $call) = @_;
+ my $req = HTTP::Request->new(
+ map { $c->req->$_ } qw/method uri headers/
+ );
+ my $body = $c->req->body;
+ my $body_content = '';
+
+ $req->content_type($c->req->content_type); # set this now so we can override
+
+ if ($body) { # Slurp from body filehandle
+ local $/; $body_content = <$body>;
+ } else {
+ my $body_params = $c->req->body_parameters;
+ if (keys %$body_params) {
+ my @parts;
+ foreach my $key (keys %$body_params) {
+ my $raw = $body_params->{$key};
+ foreach my $value (ref $raw ? @$raw : ($raw)) {
+ push(@parts, join('=', map { uri_escape($_) } ($key, $value)));
+ }
+ }
+ $body_content = join('&', @parts);
+ $req->content_type('application/x-www-form-urlencoded');
+ }
+ }
+
+ #warn "Body type: ".$req->content_type;
+ #warn "Body: ${body_content}";
+
+ $req->content($body_content);
+ $req->content_length(length($body_content));
+ my $user = (($c->can('user_exists') && $c->user_exists)
+ ? $c->user_object->username
+ : '');
+ my $env = HTTP::Request::AsCGI->new(
+ $req,
+ REMOTE_USER => $user,
+ PERL5LIB => $ENV{PERL5LIB} # propagate custom perl lib paths
+ );
+
+ {
+ local *STDIN = \*REAL_STDIN; # restore the real ones so the filenos
+ local *STDOUT = \*REAL_STDOUT; # are 0 and 1 for the env setup
+
+ my $old = select(REAL_STDOUT); # in case somebody just calls 'print'
+
+ my $saved_error;
+
+ $env->setup;
+ eval { $call->() };
+ $saved_error = $@;
+ $env->restore;
+
+ select($old);
+
+ warn "CGI invoke failed: $saved_error" if $saved_error;
+
+ }
+
+ return $env->response;
+}
+
+1;
Modified: trunk/examples/CatalystAdvent/Makefile.PL
===================================================================
--- trunk/examples/CatalystAdvent/Makefile.PL 2007-05-30 10:42:00 UTC (rev 6441)
+++ trunk/examples/CatalystAdvent/Makefile.PL 2007-05-30 10:42:35 UTC (rev 6442)
@@ -10,6 +10,7 @@
requires( Catalyst => '5.60' );
requires( 'Catalyst::Plugin::DefaultEnd' );
+requires( 'Catalyst::Plugin::Unicode' );
requires( 'Catalyst::Plugin::Cache::FileCache' );
requires( 'DateTime' );
requires( 'File::stat' );
Modified: trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
===================================================================
--- trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm 2007-05-30 10:42:00 UTC (rev 6441)
+++ trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm 2007-05-30 10:42:35 UTC (rev 6442)
@@ -90,8 +90,13 @@
MakeIndex => 0,
TopLinks => 0
);
- $parser->parse_from_file("$file");
+
+ open my $fh, '<:utf8', $file or die "Failed to open $file: $!";
+ $parser->parse_from_filehandle($fh);
+ close $fh;
+
$cached_pod = $parser->asString;
+ print {*STDERR} "hey pod: $cached_pod\n";
$c->cache->set( "$file $mtime", $cached_pod, '12h' );
}
$c->stash->{pod} = $cached_pod;
@@ -171,8 +176,11 @@
TopLinks => 0
);
- $parser->parse_from_file( ''. $path{ $day } );
-
+ my $file = q{}. $path{$day};
+ open my $fh, '<:utf8', $file or die "Failed to open $file: $!";
+ $parser->parse_from_filehandle($fh);
+ close $fh;
+
$feed->add_entry(
title => { type => 'text', content => $parser->summary },
content => { type => 'xhtml', content => $parser->asString },
Modified: trunk/examples/CatalystAdvent/lib/CatalystAdvent.pm
===================================================================
--- trunk/examples/CatalystAdvent/lib/CatalystAdvent.pm 2007-05-30 10:42:00 UTC (rev 6441)
+++ trunk/examples/CatalystAdvent/lib/CatalystAdvent.pm 2007-05-30 10:42:35 UTC (rev 6442)
@@ -5,7 +5,9 @@
use Catalyst qw( Static::Simple
Cache::FileCache
- DefaultEnd );
+ DefaultEnd
+ Unicode
+ );
our $VERSION = '0.03';
More information about the Catalyst-commits
mailing list