E.g. <media_prefix>http://static.example.com/media</media_prefix> -->
<media_prefix/>
+ <!-- If set to true, all output will be parsed as XML before delivery to the client.
+ If XML parsing fails, the error message, with HTML included, will be output as text/plain.
+ XML parsing adds overhead, so this should only be used for debugging -->
+ <force_valid_xml>false</force_valid_xml>
+
<!-- Where templates can be found. Paths will be checked in the order entered here.
It's possible to override individual or sets of templates by putting them into
a path in front of the default template path -->
$r->content_type('text/html; encoding=utf8');
my $tt = Template->new({
- OUTPUT => $r,
+ OUTPUT => ($ctx->{force_valid_xml}) ? sub { validate_as_xml($r, @_); } : $r,
INCLUDE_PATH => $ctx->{template_paths},
});
return Apache2::Const::OK;
}
+sub validate_as_xml {
+ my $r = shift;
+ my $data = shift;
+ eval { XML::Simple->new->XMLin($data); };
+ if($@) {
+ my $err = "Invalid XML: $@";
+ $r->log->error($err);
+ $r->content_type('text/plain; encoding=utf8');
+ $r->print("\n$err\n\n$data");
+ } else {
+ $r->print($data);
+ }
+}
+
+
sub load_context {
my $r = shift;
my $cgi = CGI->new;
$ctx->{media_prefix} = (ref $data->{media_prefix}) ? '' : $data->{media_prefix};
$ctx->{base_uri} = (ref $data->{base_uri}) ? '' : $data->{base_uri};
$ctx->{template_paths} = [];
+ $ctx->{force_valid_xml} = ($data->{force_valid_xml} =~ /true/io) ? 1 : 0;
my $tpaths = $data->{template_paths}->{path};
$tpaths = [$tpaths] unless ref $tpaths;