Skip to content

fix: throw error on read-only template metadata assignment (GH #270)#428

Open
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-readonly-template-assign
Open

fix: throw error on read-only template metadata assignment (GH #270)#428
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-readonly-template-assign

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

What

Assigning to template metadata now throws a file exception instead of silently failing.

Why

Fixes GH #270. [% template.foo = "blech" %] after [% META foo = "bar" %] silently did nothing — the value stayed unchanged with no error. This violates the principle of least surprise and makes debugging template issues harder.

How

Template::Document::AUTOLOAD is the read-only accessor for metadata items. When the Stash calls it with arguments (indicating an assignment via _assign()), it now dies with a Template::Exception of type file. This integrates cleanly with TRY/CATCH and the standard error handling pipeline.

The fix is minimal: 4 lines added to AUTOLOAD to detect arguments and throw.

Testing

  • Added 2 test cases to t/document.t: readonly assignment raises a catchable file error, and metadata reading still works
  • Full test suite passes: 2896 tests across 112 files

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 28 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Template metadata set via [% META %] is read-only, but assigning to it
(e.g. [% template.foo = "blech" %]) silently failed — the value simply
didn't change, with no error. Now throws a 'file' exception that can be
caught with TRY/CATCH or will surface as a proper error.

Root cause: Document's AUTOLOAD only returned $self->{$method}, ignoring
any arguments. The Stash._assign() path called $doc->foo($value) which
AUTOLOAD swallowed. Fix: detect arguments in AUTOLOAD and die with a
Template::Exception.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@toddr-bot
Copy link
Copy Markdown
Contributor Author

Recreated from #351 (auto-closed when the toddr-bot fork was removed). Original branch is now hosted on this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant