Checking in changes prior to tagging of version 1.000. Changelog diff is:
[catagits/Catalyst-View-ContentNegotiation-XHTML.git] / lib / Catalyst / View / TT / XHTML.pm
CommitLineData
0f9bcf09 1package Catalyst::View::TT::XHTML;
2use strict;
3use warnings;
4use base qw/Catalyst::View::TT/;
5
cd25b1db 6our $VERSION = '1.000';
0f9bcf09 7
8sub 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
191;
20
21__END__
22
23=head1 NAME
24
25Catalyst::View::TT::XHTML - A sub-class of the standard TT view which
26serves 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
39This is a very simple sub-class of L<Catalyst::View::TT>, which sets
40the response C<Content-Type> to be C<application/xhtml+xml> if the
41user's browser sends an C<Accept> header indicating that it is willing
42to process that MIME type.
43
44Changing the C<Content-Type> causes browsers to interpret the page as
45strict XHTML, meaning that the markup must be well formed.
46
47This is useful when you're developing your application, as you know that
48all pages you view are rendered strictly, so any markup errors will show
49up at once.
50
51=head1 METHODS
52
53=head2 process
54
55Overrides the standard process method, delegating to L<Catalyst::View::TT>
56to render the template, and then changing the response C<Content-Type> if
57appropriate (from the requests C<Accept> header).
58
59=head1 BUGS
60
61There should be a more elegant way to inherit the config of your normal
62TT view.
63
64Configuration (as loaded by L<Catalyst::Plugin::ConfigLoader>) for the TT
65view is not used.
66
67No helper to generate the view file needed (just copy the code in the
68SYNOPSIS).
69
70=head1 AUTHOR
71
72Tomas Doran C<< <bobtfish@bobtfish.net> >>
73
74=head1 COPYRIGHT
75
76This module itself is copyright (c) 2008 Tomas Doran and is licensed under the same terms as Perl itself.
77
78=cut