From: Marcus Ramberg Date: Mon, 8 Sep 2008 21:05:23 +0000 (+0000) Subject: Support print for Catalyst::Request X-Git-Tag: 5.8000_03~65 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e4cc83b2533d5261266e6eddcd9e61c7c16ac676 Support print for Catalyst::Request --- diff --git a/Changes b/Changes index d898cec..d3abf54 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index b0d30d7..38b8fa5 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -2475,6 +2475,8 @@ Gary Ashton Jones Geoff Richards +ilmari: Dagfinn Ilmari Mannsåker + jcamacho: Juan Camacho Jody Belka diff --git a/lib/Catalyst/Response.pm b/lib/Catalyst/Response.pm index 545341d..8c5cc50 100644 --- a/lib/Catalyst/Response.pm +++ b/lib/Catalyst/Response.pm @@ -164,6 +164,27 @@ Writes $data to the output stream. 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. + +=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 diff --git a/t/lib/TestApp/Controller/Engine/Response/Print.pm b/t/lib/TestApp/Controller/Engine/Response/Print.pm new file mode 100644 index 0000000..1d1f52d --- /dev/null +++ b/t/lib/TestApp/Controller/Engine/Response/Print.pm @@ -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; diff --git a/t/live_engine_response_print.t b/t/live_engine_response_print.t new file mode 100644 index 0000000..b6c6446 --- /dev/null +++ b/t/live_engine_response_print.t @@ -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" ); +}