[Catalyst-commits] r8850 - in Catalyst-View-TT-XHTML/1.000/trunk: . lib/Catalyst/View/TT t

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Fri Dec 12 18:54:35 GMT 2008


Author: t0m
Date: 2008-12-12 18:54:35 +0000 (Fri, 12 Dec 2008)
New Revision: 8850

Modified:
   Catalyst-View-TT-XHTML/1.000/trunk/Changes
   Catalyst-View-TT-XHTML/1.000/trunk/Makefile.PL
   Catalyst-View-TT-XHTML/1.000/trunk/README
   Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/TT/XHTML.pm
   Catalyst-View-TT-XHTML/1.000/trunk/t/live-test.t
   Catalyst-View-TT-XHTML/1.000/trunk/t/podspelling.t
Log:
Checking in changes prior to tagging of version 1.001.  Changelog diff is:

=== Changes
==================================================================
--- Changes	(revision 9983)
+++ Changes	(local)
@@ -1,6 +1,7 @@
+1.001 2008-12-12
   - Add tests for other Accept header cases where the current code
     will get it wrong (David Dorward)
-1.000
+  - Fix all of these tests (t0m)
+1.000 2008-12-12
   - First working version of the module extracted from the quick hack
     I have in every Catalyst application I've ever written.
-    


Modified: Catalyst-View-TT-XHTML/1.000/trunk/Changes
===================================================================
--- Catalyst-View-TT-XHTML/1.000/trunk/Changes	2008-12-12 17:15:40 UTC (rev 8849)
+++ Catalyst-View-TT-XHTML/1.000/trunk/Changes	2008-12-12 18:54:35 UTC (rev 8850)
@@ -1,6 +1,7 @@
+1.001 2008-12-12
   - Add tests for other Accept header cases where the current code
     will get it wrong (David Dorward)
-1.000
+  - Fix all of these tests (t0m)
+1.000 2008-12-12
   - First working version of the module extracted from the quick hack
     I have in every Catalyst application I've ever written.
-    

Modified: Catalyst-View-TT-XHTML/1.000/trunk/Makefile.PL
===================================================================
--- Catalyst-View-TT-XHTML/1.000/trunk/Makefile.PL	2008-12-12 17:15:40 UTC (rev 8849)
+++ Catalyst-View-TT-XHTML/1.000/trunk/Makefile.PL	2008-12-12 18:54:35 UTC (rev 8850)
@@ -5,6 +5,7 @@
 
 requires 'Catalyst::Runtime';
 requires 'Catalyst::View::TT';
+requires 'HTTP::Negotiate';
 
 build_requires 'Catalyst::Action::RenderView';
 build_requires 'Test::WWW::Mechanize::Catalyst';

Modified: Catalyst-View-TT-XHTML/1.000/trunk/README
===================================================================
--- Catalyst-View-TT-XHTML/1.000/trunk/README	2008-12-12 17:15:40 UTC (rev 8849)
+++ Catalyst-View-TT-XHTML/1.000/trunk/README	2008-12-12 18:54:35 UTC (rev 8850)
@@ -1,91 +1,51 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<title>Catalyst::View::TT::XHTML - A sub-class of the standard TT view which
-serves application/xhtml+xml content if the browser accepts it.</title>
-<link rev="made" href="mailto:root at b45.apple.com" />
-</head>
+NAME
+    Catalyst::View::TT::XHTML - A sub-class of the standard TT view which
+    serves application/xhtml+xml content if the browser accepts it.
 
-<body style="background-color: white">
+SYNOPSIS
+        package MyApp::View::XHTML;
+        use strict;
+        use warnings;
+        use base qw/Catalyst::View::TT::XHTML MyApp::View::TT/;
+    
+        1;
+    
+DESCRIPTION
+    This is a very simple sub-class of Catalyst::View::TT, which sets the
+    response "Content-Type" to be "application/xhtml+xml" if the user's
+    browser sends an "Accept" header indicating that it is willing to
+    process that MIME type.
 
-<p><a name="__index__"></a></p>
-<!-- INDEX BEGIN -->
+    Changing the "Content-Type" causes browsers to interpret the page as
+    strict XHTML, meaning that the markup must be well formed.
 
-<ul>
+    This is useful when you're developing your application, as you know that
+    all pages you view are rendered strictly, so any markup errors will show
+    up at once.
 
-	<li><a href="#name">NAME</a></li>
-	<li><a href="#synopsis">SYNOPSIS</a></li>
-	<li><a href="#methods">METHODS</a></li>
-	<ul>
+METHODS
+  process
+    Overrides the standard process method, delegating to Catalyst::View::TT
+    to render the template, and then changing the response "Content-Type" if
+    appropriate (from the requests "Accept" header).
 
-		<li><a href="#process">process</a></li>
-	</ul>
+BUGS
+    There should be a more elegant way to inherit the config of your normal
+    TT view.
 
-	<li><a href="#bugs">BUGS</a></li>
-	<li><a href="#author">AUTHOR</a></li>
-	<li><a href="#copyright">COPYRIGHT</a></li>
-</ul>
-<!-- INDEX END -->
+    Configuration (as loaded by Catalyst::Plugin::ConfigLoader) for the TT
+    view is not used.
 
-<hr />
-<p>
-</p>
-<h1><a name="name">NAME</a></h1>
-<p>Catalyst::View::TT::XHTML - A sub-class of the standard TT view which
-serves application/xhtml+xml content if the browser accepts it.</p>
-<p>
-</p>
-<hr />
-<h1><a name="synopsis">SYNOPSIS</a></h1>
-<pre>
-    package MyApp::View::XHTML;
-    use strict;
-    use warnings;
-    use base qw/Catalyst::View::TT::XHTML MyApp::View::TT/;
-    
-    1;
-    
-=head1 DESCRIPTION</pre>
-<p>This is a very simple sub-class of <a href="/Catalyst/View/TT.html">the Catalyst::View::TT manpage</a>, which sets
-the response <code>Content-Type</code> to be <code>application/xhtml+xml</code> if the
-user's browser sends an <code>Accept</code> header indicating that it is willing
-to process that MIME type.</p>
-<p>Changing the <code>Content-Type</code> causes browsers to interpret the page as
-strict XHTML, meaning that the markup must be well formed.</p>
-<p>This is useful when you're developing your application, as you know that
-all pages you view are rendered strictly, so any markup errors will show
-up at once.</p>
-<p>
-</p>
-<hr />
-<h1><a name="methods">METHODS</a></h1>
-<p>
-</p>
-<h2><a name="process">process</a></h2>
-<p>Overrides the standard process method, delegating to <a href="/Catalyst/View/TT.html">the Catalyst::View::TT manpage</a>
-to render the template, and then changing the response <code>Content-Type</code> if
-appropriate (from the requests <code>Accept</code> header).</p>
-<p>
-</p>
-<hr />
-<h1><a name="bugs">BUGS</a></h1>
-<p>There should be a more elegant way to inherit the config of your normal 
-TT view.</p>
-<p>Configuration (as loaded by <a href="/Catalyst/Plugin/ConfigLoader.html">the Catalyst::Plugin::ConfigLoader manpage</a>) for the TT 
-view is not used.</p>
-<p>No helper to generate the view file needed (just copy the code in the 
-SYNOPSIS).</p>
-<p>
-</p>
-<hr />
-<h1><a name="author">AUTHOR</a></h1>
-<p>Tomas Doran <code>&lt;bobtfish at bobtfish.net&gt;</code></p>
-<p>
-</p>
-<hr />
-<h1><a name="copyright">COPYRIGHT</a></h1>
-<p>This module itself is copyright (c) 2008 Tomas Doran and is licensed under the same terms as Perl itself.</p>
+    No helper to generate the view file needed (just copy the code in the
+    SYNOPSIS).
 
-</body>
+AUTHOR
+    Tomas Doran "<bobtfish at bobtfish.net>"
 
-</html>
+CONTRIBUTORS
+    David Dorward - test patches
+
+COPYRIGHT
+    This module itself is copyright (c) 2008 Tomas Doran and is licensed
+    under the same terms as Perl itself.
+

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	2008-12-12 17:15:40 UTC (rev 8849)
+++ Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/TT/XHTML.pm	2008-12-12 18:54:35 UTC (rev 8850)
@@ -1,19 +1,28 @@
 package Catalyst::View::TT::XHTML;
 use strict;
 use warnings;
+use HTTP::Negotiate qw(choose);
 use base qw/Catalyst::View::TT/;
 
-our $VERSION = '1.000';
+our $VERSION = '1.001';
 
+our $variants = [
+    [qw| xhtml 1.000 application/xhtml+xml |],
+    [qw| html  0.001 text/html             |],
+];
+
 sub process {
     my $self = shift;
     my ($c) = @_;
-    $self->next::method(@_);
-    my $accept = $c->request->header('Accept');
-    if ( $accept && $accept =~ m|application/xhtml\+xml|) {
-      $c->response->headers->{'content-type'} =~ s|text/html|application/xhtml+xml|;
+    my $return = $self->next::method(@_);
+   
+    if ($c->request->header('Accept') && $c->response->headers->{'content-type'} =~ m|text/html|) {
+        my $var = choose($variants, $c->request->headers);
+        if ($var eq 'xhtml') {
+            $c->response->headers->{'content-type'} =~ s|text/html|application/xhtml+xml|;
+        }
     }
-    return 1;
+    return $return;
 }
 
 1;

Modified: Catalyst-View-TT-XHTML/1.000/trunk/t/live-test.t
===================================================================
--- Catalyst-View-TT-XHTML/1.000/trunk/t/live-test.t	2008-12-12 17:15:40 UTC (rev 8849)
+++ Catalyst-View-TT-XHTML/1.000/trunk/t/live-test.t	2008-12-12 18:54:35 UTC (rev 8850)
@@ -59,7 +59,7 @@
   'Accept header of application/xhtml+xml with q value of 0 and text/html = text/html';
 
 # 20-22
-$mech->add_header( Accept => 'text/html;q=0');
+$mech->add_header( Accept => 'text/html;q=0, application/xhtml+xml');
 $mech->get_ok('http://localhost/', 'get main page');
 $mech->content_like(qr/it works/i, 'see if it has our text');
 is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8',

Modified: Catalyst-View-TT-XHTML/1.000/trunk/t/podspelling.t
===================================================================
--- Catalyst-View-TT-XHTML/1.000/trunk/t/podspelling.t	2008-12-12 17:15:40 UTC (rev 8849)
+++ Catalyst-View-TT-XHTML/1.000/trunk/t/podspelling.t	2008-12-12 18:54:35 UTC (rev 8850)
@@ -17,3 +17,4 @@
 XHTML
 TT
 Doran
+Dorward




More information about the Catalyst-commits mailing list