Commit | Line | Data |
0f9bcf09 |
1 | package Catalyst::View::TT::XHTML; |
2 | use strict; |
3 | use warnings; |
4 | use base qw/Catalyst::View::TT/; |
5 | |
cd25b1db |
6 | our $VERSION = '1.000'; |
0f9bcf09 |
7 | |
8 | sub process { |
9 | my $self = shift; |
10 | my ($c) = @_; |
11 | $self->next::method(@_); |
12 | my $accept = $c->request->header('Accept'); |
13 | if ( $accept && $accept =~ m|application/xhtml\+xml|) { |
14 | $c->response->headers->{'content-type'} =~ s|text/html|application/xhtml+xml|; |
15 | } |
16 | return 1; |
17 | } |
18 | |
19 | 1; |
20 | |
21 | __END__ |
22 | |
23 | =head1 NAME |
24 | |
25 | Catalyst::View::TT::XHTML - A sub-class of the standard TT view which |
26 | serves application/xhtml+xml content if the browser accepts it. |
27 | |
28 | =head1 SYNOPSIS |
29 | |
30 | package MyApp::View::XHTML; |
31 | use strict; |
32 | use warnings; |
33 | use base qw/Catalyst::View::TT::XHTML MyApp::View::TT/; |
34 | |
35 | 1; |
36 | |
37 | =head1 DESCRIPTION |
38 | |
39 | This is a very simple sub-class of L<Catalyst::View::TT>, which sets |
40 | the response C<Content-Type> to be C<application/xhtml+xml> if the |
41 | user's browser sends an C<Accept> header indicating that it is willing |
42 | to process that MIME type. |
43 | |
44 | Changing the C<Content-Type> causes browsers to interpret the page as |
45 | strict XHTML, meaning that the markup must be well formed. |
46 | |
47 | This is useful when you're developing your application, as you know that |
48 | all pages you view are rendered strictly, so any markup errors will show |
49 | up at once. |
50 | |
51 | =head1 METHODS |
52 | |
53 | =head2 process |
54 | |
55 | Overrides the standard process method, delegating to L<Catalyst::View::TT> |
56 | to render the template, and then changing the response C<Content-Type> if |
57 | appropriate (from the requests C<Accept> header). |
58 | |
59 | =head1 BUGS |
60 | |
61 | There should be a more elegant way to inherit the config of your normal |
62 | TT view. |
63 | |
64 | Configuration (as loaded by L<Catalyst::Plugin::ConfigLoader>) for the TT |
65 | view is not used. |
66 | |
67 | No helper to generate the view file needed (just copy the code in the |
68 | SYNOPSIS). |
69 | |
70 | =head1 AUTHOR |
71 | |
72 | Tomas Doran C<< <bobtfish@bobtfish.net> >> |
73 | |
74 | =head1 COPYRIGHT |
75 | |
76 | This module itself is copyright (c) 2008 Tomas Doran and is licensed under the same terms as Perl itself. |
77 | |
78 | =cut |