Commit | Line | Data |
e601adda |
1 | package Catalyst::Action::Serialize::YAML::HTML; |
2 | |
930013e6 |
3 | use Moose; |
4 | use namespace::autoclean; |
e601adda |
5 | |
930013e6 |
6 | extends 'Catalyst::Action'; |
e601adda |
7 | use YAML::Syck; |
8 | use URI::Find; |
9 | |
10 | sub execute { |
11 | my $self = shift; |
12 | my ( $controller, $c ) = @_; |
13 | |
faf5c20b |
14 | my $stash_key = ( |
07682cbc |
15 | $controller->{'serialize'} ? |
16 | $controller->{'serialize'}->{'stash_key'} : |
17 | $controller->{'stash_key'} |
faf5c20b |
18 | ) || 'rest'; |
e601adda |
19 | my $app = $c->config->{'name'} || ''; |
20 | my $output = "<html>"; |
21 | $output .= "<title>" . $app . "</title>"; |
22 | $output .= "<body><pre>"; |
23 | my $text = Dump($c->stash->{$stash_key}); |
24 | # Straight from URI::Find |
25 | my $finder = URI::Find->new( |
26 | sub { |
27 | my($uri, $orig_uri) = @_; |
a621925a |
28 | my $newuri; |
f7218d54 |
29 | if ($uri =~ /\?/) { |
a621925a |
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>|; |
e601adda |
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 | 1; |