[Catalyst-commits] r9147 - in
Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role: .
lib/Catalyst/View lib/Catalyst/View/ContentNegotiation
lib/Catalyst/View/TT
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Fri Jan 30 10:42:35 GMT 2009
Author: t0m
Date: 2009-01-30 10:42:34 +0000 (Fri, 30 Jan 2009)
New Revision: 9147
Added:
Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/lib/Catalyst/View/ContentNegotiation/
Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/lib/Catalyst/View/ContentNegotiation/XHTML.pm
Modified:
Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/Makefile.PL
Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/lib/Catalyst/View/TT/XHTML.pm
Log:
Patch to turn this into a Moose Role (much more sane) from rafl, POD to come
Modified: Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/Makefile.PL
===================================================================
--- Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/Makefile.PL 2009-01-30 10:41:17 UTC (rev 9146)
+++ Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/Makefile.PL 2009-01-30 10:42:34 UTC (rev 9147)
@@ -6,7 +6,10 @@
requires 'Catalyst::Runtime';
requires 'Catalyst::View::TT';
requires 'HTTP::Negotiate';
-requires 'MRO::Compat';
+requires 'Moose';
+requires 'MooseX::Types::Moose';
+requires 'MooseX::Types::Structured';
+requires 'namespace::clean';
build_requires 'Catalyst::Action::RenderView';
build_requires 'Test::WWW::Mechanize::Catalyst';
@@ -32,4 +35,5 @@
}
}
+auto_install();
WriteAll();
Added: Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/lib/Catalyst/View/ContentNegotiation/XHTML.pm
===================================================================
--- Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/lib/Catalyst/View/ContentNegotiation/XHTML.pm (rev 0)
+++ Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/lib/Catalyst/View/ContentNegotiation/XHTML.pm 2009-01-30 10:42:34 UTC (rev 9147)
@@ -0,0 +1,48 @@
+package Catalyst::View::ContentNegotiation::XHTML;
+
+use Moose::Role;
+use MooseX::Types::Moose qw/Num Str ArrayRef/;
+use MooseX::Types::Structured qw/Tuple/;
+use HTTP::Negotiate qw/choose/;
+
+use namespace::clean -except => 'meta';
+
+our $VERSION = '1.004';
+
+has variants => (
+ is => 'ro',
+ isa => ArrayRef[Tuple[Str, Num, Str]],
+ lazy => 1,
+ builder => '_build_variants',
+);
+
+sub _build_variants {
+ return [
+ [qw| xhtml 1.000 application/xhtml+xml |],
+ [qw| html 0.900 text/html |],
+ ];
+}
+
+after process => sub {
+ my ($self, $c) = @_;
+ if ($c->request->header('Accept') && $c->response->headers->{'content-type'} =~ m|text/html|) {
+ $self->pragmatic_accept($c);
+ my $var = choose($self->variants, $c->request->headers);
+ if ($var eq 'xhtml') {
+ $c->response->headers->{'content-type'} =~ s|text/html|application/xhtml+xml|;
+ }
+ }
+};
+
+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);
+}
+
+1;
Modified: Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/lib/Catalyst/View/TT/XHTML.pm
===================================================================
--- Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/lib/Catalyst/View/TT/XHTML.pm 2009-01-30 10:41:17 UTC (rev 9146)
+++ Catalyst-View-TT-XHTML/1.000/branches/refactor-into-role/lib/Catalyst/View/TT/XHTML.pm 2009-01-30 10:42:34 UTC (rev 9147)
@@ -1,42 +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/;
-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;
-}
+our $VERSION = '1.004';
-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);
-}
-
1;
__END__
More information about the Catalyst-commits
mailing list