[Catalyst-commits] r8368 - in Catalyst-Runtime/5.80/trunk: . lib lib/Catalyst t t/lib/TestApp/Controller/Engine/Response

marcus at dev.catalyst.perl.org marcus at dev.catalyst.perl.org
Mon Sep 8 22:05:23 BST 2008


Author: marcus
Date: 2008-09-08 22:05:23 +0100 (Mon, 08 Sep 2008)
New Revision: 8368

Added:
   Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Engine/Response/Print.pm
   Catalyst-Runtime/5.80/trunk/t/live_engine_response_print.t
Modified:
   Catalyst-Runtime/5.80/trunk/Changes
   Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Response.pm
Log:
Support print for Catalyst::Request

Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes	2008-09-08 20:45:05 UTC (rev 8367)
+++ Catalyst-Runtime/5.80/trunk/Changes	2008-09-08 21:05:23 UTC (rev 8368)
@@ -4,7 +4,9 @@
         - Port to Moose
         - Added test for action stringify
         - Added test for component instances getting $self->{value} from config.
-        - Chained doc improvements (rev 8326-8328)
+        - Add Catalyst::Response->print() method (ilmari)
+         
+         ))
 
 5.7XXXXXX XXXX
         - Fix some Win32 test failures

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Response.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Response.pm	2008-09-08 20:45:05 UTC (rev 8367)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Response.pm	2008-09-08 21:05:23 UTC (rev 8368)
@@ -164,6 +164,27 @@
 
 Provided by Moose
 
+=head2 $res->print( @data )
+
+Prints @data to the output stream, separated by $,.  This lets you pass
+the response object to functions that want to write to an L<IO::Handle>.
+
+=cut
+
+sub print {
+    my $self = shift;
+    my $data = shift;
+
+    defined $self->write($data) or return;
+
+    for (@_) {
+        defined $self->write($,) or return;
+        defined $self->write($_) or return;
+    }
+    
+    return 1;
+}
+
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2008-09-08 20:45:05 UTC (rev 8367)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2008-09-08 21:05:23 UTC (rev 8368)
@@ -2475,6 +2475,8 @@
 
 Geoff Richards
 
+ilmari: Dagfinn Ilmari Mannsåker <ilmari at ilmari.org>
+
 jcamacho: Juan Camacho
 
 Jody Belka

Added: Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Engine/Response/Print.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Engine/Response/Print.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Engine/Response/Print.pm	2008-09-08 21:05:23 UTC (rev 8368)
@@ -0,0 +1,25 @@
+package TestApp::Controller::Engine::Response::Print;
+
+use strict;
+use base 'Catalyst::Base';
+
+sub one :Relative {
+    my ( $self, $c ) = @_;
+    
+    $c->res->print("foo");
+}
+
+sub two :Relative {
+    my ( $self, $c ) = @_;
+
+    $c->res->print(qw/foo bar/);
+}
+
+sub three :Relative {
+    my ( $self, $c ) = @_;
+
+    local $, = ',';
+    $c->res->print(qw/foo bar baz/);
+}
+
+1;

Added: Catalyst-Runtime/5.80/trunk/t/live_engine_response_print.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/live_engine_response_print.t	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/live_engine_response_print.t	2008-09-08 21:05:23 UTC (rev 8368)
@@ -0,0 +1,24 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 9;
+use Catalyst::Test 'TestApp';
+
+my $expected = {
+   one => "foo",
+   two => "foobar",
+   three => "foo,bar,baz",
+};
+
+for my $action ( keys %{$expected} ) {
+    ok( my $response = request('http://localhost/engine/response/print/' . $action ),
+        'Request' );
+    ok( $response->is_success, "Response $action successful 2xx" );
+    
+    is( $response->content, $expected->{$action}, "Content $action OK" );
+}




More information about the Catalyst-commits mailing list