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 | |
7566d72f |
10 | our $VERSION = '1.13'; |
f465980c |
11 | $VERSION = eval $VERSION; |
12 | |
e601adda |
13 | sub execute { |
14 | my $self = shift; |
15 | my ( $controller, $c ) = @_; |
16 | |
faf5c20b |
17 | my $stash_key = ( |
07682cbc |
18 | $controller->{'serialize'} ? |
19 | $controller->{'serialize'}->{'stash_key'} : |
20 | $controller->{'stash_key'} |
faf5c20b |
21 | ) || 'rest'; |
e601adda |
22 | my $app = $c->config->{'name'} || ''; |
23 | my $output = "<html>"; |
24 | $output .= "<title>" . $app . "</title>"; |
25 | $output .= "<body><pre>"; |
8aa1a2ee |
26 | my $text = HTML::Entities::encode(Dump($c->stash->{$stash_key})); |
e601adda |
27 | # Straight from URI::Find |
28 | my $finder = URI::Find->new( |
29 | sub { |
30 | my($uri, $orig_uri) = @_; |
a621925a |
31 | my $newuri; |
f7218d54 |
32 | if ($uri =~ /\?/) { |
a621925a |
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>|; |
e601adda |
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 | |
24748286 |
48 | __PACKAGE__->meta->make_immutable; |
49 | |
e601adda |
50 | 1; |