Made the YAML::HTML view automatically append the content-type to it's URLs, since...
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / YAML / HTML.pm
CommitLineData
e601adda 1#
2# Catlyst::Action::Serialize::YAML::HTML.pm
3# Created by: Adam Jacob, Marchex, <adam@marchex.com>
4# Created on: 10/12/2006 03:00:32 PM PDT
5#
6# $Id$
7
8package Catalyst::Action::Serialize::YAML::HTML;
9
10use strict;
11use warnings;
12
13use base 'Catalyst::Action';
14use YAML::Syck;
15use URI::Find;
16
17sub execute {
18 my $self = shift;
19 my ( $controller, $c ) = @_;
20
21 my $stash_key = $controller->config->{'serialize'}->{'stash_key'} || 'rest';
22 my $app = $c->config->{'name'} || '';
23 my $output = "<html>";
24 $output .= "<title>" . $app . "</title>";
25 $output .= "<body><pre>";
26 my $text = Dump($c->stash->{$stash_key});
27 # Straight from URI::Find
28 my $finder = URI::Find->new(
29 sub {
30 my($uri, $orig_uri) = @_;
a621925a 31 my $newuri;
32 if ($uri =~ /?/) {
33 $newuri = $uri . "&content-type=text/html";
34 } else {
35 $newuri = $uri . "?content-type=text/html";
36 }
37 return qq|<a href="$newuri">$orig_uri</a>|;
e601adda 38 });
39 $finder->find(\$text);
40 $output .= $text;
41 $output .= "</pre>";
42 $output .= "</body>";
43 $output .= "</html>";
44 $c->response->output( $output );
45 return 1;
46}
47
481;