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