Commit | Line | Data |
e601adda |
1 | # |
2 | # Catlyst::Action::Serialize::YAML::HTML.pm |
3 | # Created by: Adam Jacob, Marchex, <adam@marchex.com> |
4 | # Created on: 10/12/2006 03:00:32 PM PDT |
5 | # |
6 | # $Id$ |
7 | |
8 | package Catalyst::Action::Serialize::YAML::HTML; |
9 | |
10 | use strict; |
11 | use warnings; |
12 | |
13 | use base 'Catalyst::Action'; |
14 | use YAML::Syck; |
15 | use URI::Find; |
16 | |
17 | sub execute { |
18 | my $self = shift; |
19 | my ( $controller, $c ) = @_; |
20 | |
21 | my $stash_key = $controller->config->{'serialize'}->{'stash_key'} || 'rest'; |
22 | my $app = $c->config->{'name'} || ''; |
23 | my $output = "<html>"; |
24 | $output .= "<title>" . $app . "</title>"; |
25 | $output .= "<body><pre>"; |
26 | my $text = Dump($c->stash->{$stash_key}); |
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 | |
48 | 1; |