Die folgenden Fälle werden nun für $template wie folgt behandelt:
- keine Ref: $tempalte wird als Dateiname interpretiert
- Ref auf einen String (ref eq 'SCALAR'): Zu rendernder String,
direkte Übergabe an Template
- Instanz von EscapedText und Ref auf Instanz von EscapedText: Zu
rendernder String ist der von EscapedText geproxite Text, direkte
Übergabe an Template mit "process => 1" und direktes Zurückgeben mit
"process => 0"
Damit ist es aus Caller-Sicht einfacher, den Aufruf richtig
hinzubekommen:
my $some_result = $self->presenter->grouped_record_list($objects);
# Don't care whether or not $some_result is already an instance of
# EscapedText: never treat this as a file name
$self->render(\$some_result, { layout => 0 });
croak "Unsupported type: " . $options->{type} unless $options->{type} =~ m/^(?:html|js|json)$/;
# The "template" argument must be a string or a reference to one.
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)$/);
# If all output is turned off then don't output the header either.
croak "Unsupported 'template' reference type: " . ref($template) if ref($template) && (ref($template) !~ m/^(?:SCALAR|SL::Presenter::EscapedText)$/);
# If all output is turned off then don't output the header either.
croak "Unsupported type: " . $options->{type} unless $options->{type} =~ m/^(?:html|js|json)$/;
# The "template" argument must be a string or a reference to one.
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.
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.
# 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.
# 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");
# Otherwise return the file's content.
my $file = IO::File->new($source, "r") || croak("Template file ${source} could not be read");