Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/Template/Document.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use strict;
use warnings;
use base 'Template::Base';
use Template::Constants;
use Template::Exception;

our $VERSION = '3.100';
our $DEBUG = 0 unless defined $DEBUG;
Expand Down Expand Up @@ -205,8 +206,14 @@ sub AUTOLOAD {

$method =~ s/.*:://;
return if $method eq 'DESTROY';
# my ($pkg, $file, $line) = caller();
# print STDERR "called $self->AUTOLOAD($method) from $file line $line\n";

# metadata items are read-only; throw an error if called with arguments
# (which indicates an assignment attempt via the stash)
if (@_) {
die Template::Exception->new('file',
"template metadata item '$method' is read-only");
}

return $self->{ $method };
}

Expand Down
19 changes: 19 additions & 0 deletions t/document.t
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ title: My Template Title
-- expect --
some output

-- test --
# GH #270: assigning to template metadata should throw, not silently fail
[% META foo = 'bar' -%]
[% TRY -%]
[% template.foo = 'blech' -%]
ERROR: no exception raised
[% CATCH file -%]
OK: [% error.info %]
[% END %]
-- expect --
OK: template metadata item 'foo' is read-only

-- test --
# reading metadata still works after the readonly check
[% META title = 'Read Test' version = 42 -%]
title=[% template.title %] version=[% template.version %]
-- expect --
title=Read Test version=42

-- stop --
# test for component.caller and component.callers patch
-- test --
Expand Down
Loading