4773c0b323b6d2533b37b2671fe5874b70ed8929
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / YAML / HTML.pm
1 package Catalyst::Action::Serialize::YAML::HTML;
2 use Moose;
3 extends 'Catalyst::Action::Serialize::YAML';
4 use URI::Find;
5 use namespace::clean -except => 'meta';
6
7 around serialize => sub {
8   my $next = shift;
9   my ($self, $data, $c) = @_;
10   my $yaml = $self->$next($data, $c);
11   my $app = $c->config->{name} || '';
12   my $finder = URI::Find->new(sub {
13     my($uri, $orig_uri) = @_;
14     my $newuri;
15     if ($uri =~ /\?/) {
16         $newuri = $uri . "&content-type=text/html";
17     } else {
18         $newuri = $uri . "?content-type=text/html";
19     }
20     return qq|<a href="$newuri">$orig_uri</a>|;
21   });
22   my $output = "<html>";
23   $output .= "<title>" . $app . "</title>";
24   $output .= "<body><pre>";
25   $finder->find(\$yaml);
26   $output .= $yaml;
27   $output .= "</pre>";
28   $output .= "</body>";
29   $output .= "</html>";
30   return $output;
31 };
32
33 1;