Added otional status to $c->response->redirect
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Response.pm
1 package Catalyst::Response;
2
3 use strict;
4 use base 'Class::Accessor::Fast';
5
6 __PACKAGE__->mk_accessors(qw/cookies body headers location status/);
7
8 *output = \&body;
9
10 sub content_encoding { shift->headers->content_encoding(@_) }
11 sub content_length   { shift->headers->content_length(@_)   }
12 sub content_type     { shift->headers->content_type(@_)     }
13 sub header           { shift->headers->header(@_)           }
14
15 =head1 NAME
16
17 Catalyst::Response - Catalyst Response Class
18
19 =head1 SYNOPSIS
20
21     $resp = $c->response;
22     $resp->body;
23     $resp->content_encoding;
24     $resp->content_length;
25     $resp->content_type;
26     $resp->cookies;
27     $resp->header;
28     $resp->headers;
29     $resp->output;
30     $resp->redirect;
31     $resp->status;
32
33 See also L<Catalyst::Application>.
34
35 =head1 DESCRIPTION
36
37 This is the Catalyst Response class, which provides a set of accessors
38 to response data.
39
40 =head1 METHODS
41
42 =over 4
43
44 =item $resp->body($text)
45
46     $c->response->body('Catalyst rocks!');
47
48 Contains the final output.
49
50 =item $resp->content_encoding
51
52 Shortcut to $resp->headers->content_encoding
53
54 =item $resp->content_length
55
56 Shortcut to $resp->headers->content_length
57
58 =item $resp->content_type
59
60 Shortcut to $resp->headers->content_type
61
62 =item $resp->cookies
63
64 Returns a reference to a hash containing the cookies to be set.
65
66     $c->response->cookies->{foo} = { value => '123' };
67
68 =item $resp->header
69
70 Shortcut to $resp->headers->header
71
72 =item $resp->headers
73
74 Returns a L<HTTP::Headers> object containing the headers.
75
76     $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
77
78 =item $resp->output
79
80 Shortcut to $resp->body
81
82 =item $resp->redirect( $url, $status )
83
84 Contains a location to redirect to.
85
86     $c->response->redirect( 'http://slashdot.org' );
87     $c->response->redirect( 'http://slashdot.org', 307 );
88
89 =cut
90
91 sub redirect {
92     my $self = shift;
93     
94     if ( @_ ) {
95         my $location = shift;
96         my $status   = shift || 302;
97
98         $self->location($location);
99         $self->status($status);
100     }
101
102     return $self->location;
103 }
104
105 =item status
106
107 Contains the HTTP status.
108
109     $c->response->status(404);
110
111 =back
112
113 =head1 AUTHOR
114
115 Sebastian Riedel, C<sri@cpan.org>
116 Marcus Ramberg, C<mramberg@cpan.org>
117
118 =head1 COPYRIGHT
119
120 This program is free software, you can redistribute it and/or modify 
121 it under the same terms as Perl itself.
122
123 =cut
124
125 1;