Configuration patches to handle component based configuration in a sane way, as well...
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / YAML / HTML.pm
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
8 package Catalyst::Action::Serialize::YAML::HTML;
9
10 use strict;
11 use warnings;
12
13 use base 'Catalyst::Action';
14 use YAML::Syck;
15 use URI::Find;
16
17 sub execute {
18     my $self = shift;
19     my ( $controller, $c ) = @_;
20
21     my $stash_key = (
22             $controller->config->{'serialize'} ?
23                 $controller->config->{'serialize'}->{'stash_key'} :
24                 $controller->config->{'stash_key'} 
25         ) || 'rest';
26     my $app = $c->config->{'name'} || '';
27     my $output = "<html>";
28     $output .= "<title>" . $app . "</title>";
29     $output .= "<body><pre>";
30     my $text = Dump($c->stash->{$stash_key});
31     # Straight from URI::Find
32     my $finder = URI::Find->new(
33                               sub {
34                                   my($uri, $orig_uri) = @_;
35                                   my $newuri;
36                                   if ($uri =~ /\?/) {
37                                       $newuri = $uri . "&content-type=text/html";
38                                   } else {
39                                       $newuri = $uri . "?content-type=text/html";
40                                   }
41                                   return qq|<a href="$newuri">$orig_uri</a>|;
42                               });
43     $finder->find(\$text);
44     $output .= $text;
45     $output .= "</pre>";
46     $output .= "</body>";
47     $output .= "</html>";
48     $c->response->output( $output );
49     return 1;
50 }
51
52 1;