SL::{Controller,Presenter}->render: $template kann auch ref auf Instanz von EscapedTe...
[kivitendo-erp.git] / SL / Presenter.pm
index 6658184..4547ec7 100644 (file)
@@ -41,6 +41,7 @@ sub render {
   croak "Unsupported type: " . $options->{type} unless $options->{type} =~ m/^(?:html|js|json)$/;
 
   # The "template" argument must be a string or a reference to one.
+  $template = ${ $template }                                       if ((ref($template) || '') eq 'REF') && (ref(${ $template }) eq 'SL::Presenter::EscapedText');
   croak "Unsupported 'template' reference type: " . ref($template) if ref($template) && (ref($template) !~ m/^(?:SCALAR|SL::Presenter::EscapedText)$/);
 
   # Look for the file given by $template if $template is not a reference.
@@ -61,7 +62,9 @@ sub render {
   # If no processing is requested then return the content.
   if (!$options->{process}) {
     # If $template is a reference then don't try to read a file.
-    return SL::Presenter::EscapedText->new(text => ${ $template }, is_escaped => 1) if ref $template;
+    my $ref = ref $template;
+    return $template                                                                if $ref eq 'SL::Presenter::EscapedText';
+    return SL::Presenter::EscapedText->new(text => ${ $template }, is_escaped => 1) if $ref eq 'SCALAR';
 
     # Otherwise return the file's content.
     my $file    = IO::File->new($source, "r") || croak("Template file ${source} could not be read");