6d2129a35e90f214448fb3c325297faa605ed957
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / YAML / HTML.pm
1 package Catalyst::Action::Serialize::YAML::HTML;
2
3 use Moose;
4 use namespace::autoclean;
5
6 extends 'Catalyst::Action';
7 use YAML::Syck;
8 use URI::Find;
9
10 our $VERSION = '0.81';
11 $VERSION = eval $VERSION;
12
13 sub execute {
14     my $self = shift;
15     my ( $controller, $c ) = @_;
16
17     my $stash_key = (
18             $controller->{'serialize'} ?
19                 $controller->{'serialize'}->{'stash_key'} :
20                 $controller->{'stash_key'} 
21         ) || '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) = @_;
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>|;
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
48 1;