[Catalyst-commits] r9187 - Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/TT

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Tue Feb 3 21:51:13 GMT 2009


Author: t0m
Date: 2009-02-03 21:51:13 +0000 (Tue, 03 Feb 2009)
New Revision: 9187

Modified:
   Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/TT/XHTML.pm
Log:
Unfuck merge, I should stick with adding docs when I'm shattered

Modified: Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/TT/XHTML.pm
===================================================================
--- Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/TT/XHTML.pm	2009-02-03 21:32:59 UTC (rev 9186)
+++ Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/TT/XHTML.pm	2009-02-03 21:51:13 UTC (rev 9187)
@@ -1,43 +1,13 @@
 package Catalyst::View::TT::XHTML;
-use strict;
-use warnings;
-use HTTP::Negotiate qw(choose);
-use MRO::Compat;
-use base qw/Catalyst::View::TT/;
 
-# Remember to bump $VERSION in ContentNegotiation::XHTML also.
-our $VERSION = '1.004';
+use Moose;
+use namespace::clean -except => 'meta';
 
-our $variants = [
-    [qw| xhtml 1.000 application/xhtml+xml |],
-    [qw| html  0.900 text/html             |],
-];
+extends qw/Catalyst::View::TT/;
+with qw/Catalyst::View::ContentNegotiation::XHTML/;
 
-sub process {
-    my $self = shift;
-    my ($c) = @_;
-    my $return = $self->next::method(@_);
-    if ($c->request->header('Accept') && $c->response->headers->{'content-type'} =~ m|text/html|) {
-        $self->pragmatic_accept($c);
-        my $var = choose($variants, $c->request->headers);
-        if ($var eq 'xhtml') {
-            $c->response->headers->{'content-type'} =~ s|text/html|application/xhtml+xml|;
-        }
-    }
-    return $return;
-}
-
-sub pragmatic_accept {
-    my ($self, $c) = @_;
-    my $accept = $c->request->header('Accept');
-    if ($accept =~ m|text/html|) {
-        $accept =~ s!\*/\*\s*([,]+|$)!*/*;q=0.5$1!;
-    } else {
-        $accept =~ s!\*/\*\s*([,]+|$)!text/html,*/*;q=0.5$1!;
-    }
-    $c->request->header('Accept' => $accept);
-}
-
+our $VERSION = '1.100';
+   
 1;
 
 __END__
@@ -52,7 +22,7 @@
     package MyApp::View::XHTML;
     use strict;
     use warnings;
-    use base qw/Catalyst::View::TT::XHTML MyApp::View::TT/;
+    use base qw/Catalyst::View::TT::XHTML/;
 
     1;
 
@@ -70,46 +40,18 @@
 all pages you view are parsed as XML, so any errors caused by your markup
 not being well-formed will show up at once.
 
-=head1 METHODS
+=head1 NOTE 
 
-=head2 process
+This module is a very simple demonstration of a consumer of the 
+L<Catalyst::View::ContentNegotiation::XHTML> role. 
 
-Overrides the standard process method, delegating to L<Catalyst::View::TT>
-to render the template, and then changing the response C<Content-Type> if
-appropriate (from the requests C<Accept> header).
+If your needs are not trivial, then it is recommended that you consume
+that role yourself.
 
-=head2 pragmatic_accept
-
-Some browsers (such as Internet Explorer) have a nasty way of sending
-Accept */* and this claiming to support XHTML just as well as HTML.
-Saving to a file on disk or opening with another application does
-count as accepting, but it really should have a lower q value then
-text/html. This sub takes a pragmatic approach and corrects this mistake
-by modifying the Accept header before passing it to content negotiation.
-
-=head1 BUGS
-
-There should be a more elegant way to inherit the config of your normal 
-TT view.
-
-Configuration (as loaded by L<Catalyst::Plugin::ConfigLoader>) for the TT 
-view is not used.
-
-No helper to generate the view file needed (just copy the code in the 
-SYNOPSIS).
-
 =head1 AUTHOR
 
-Tomas Doran C<< <bobtfish at bobtfish.net> >>
+Tomas Doran (t0m) C<< <bobtfish at bobtfish.net> >>
 
-=head1 CONTRIBUTORS
-
-=over
-
-=item David Dorward - test patches and */* pragmatism. 
-
-=back
-
 =head1 COPYRIGHT
 
 This module itself is copyright (c) 2008 Tomas Doran and is licensed under the same terms as Perl itself.




More information about the Catalyst-commits mailing list