v1.21
[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 sub execute {
11     my $self = shift;
12     my ( $controller, $c ) = @_;
13
14     my $stash_key = (
15             $controller->{'serialize'} ?
16                 $controller->{'serialize'}->{'stash_key'} :
17                 $controller->{'stash_key'} 
18         ) || 'rest';
19     my $app = $c->config->{'name'} || '';
20     my $output = "<html>";
21     $output .= "<title>" . $app . "</title>";
22     $output .= "<body><pre>";
23     my $text = HTML::Entities::encode(Dump($c->stash->{$stash_key}));
24     # Straight from URI::Find
25     my $finder = URI::Find->new(
26                               sub {
27                                   my($uri, $orig_uri) = @_;
28                                   my $newuri;
29                                   if ($uri =~ /\?/) {
30                                       $newuri = $uri . "&content-type=text/html";
31                                   } else {
32                                       $newuri = $uri . "?content-type=text/html";
33                                   }
34                                   return qq|<a href="$newuri">$orig_uri</a>|;
35                               });
36     $finder->find(\$text);
37     $output .= $text;
38     $output .= "</pre>";
39     $output .= "</body>";
40     $output .= "</html>";
41     $c->response->output( $output );
42     return 1;
43 }
44
45 __PACKAGE__->meta->make_immutable;
46
47 1;