fix: throw error on read-only template metadata assignment (GH #270)#428
Open
toddr-bot wants to merge 1 commit into
Open
fix: throw error on read-only template metadata assignment (GH #270)#428toddr-bot wants to merge 1 commit into
toddr-bot wants to merge 1 commit into
Conversation
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>
Contributor
Author
|
Recreated from #351 (auto-closed when the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Assigning to template metadata now throws a
fileexception 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::AUTOLOADis the read-only accessor for metadata items. When the Stash calls it with arguments (indicating an assignment via_assign()), it now dies with aTemplate::Exceptionof typefile. 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
t/document.t: readonly assignment raises a catchablefileerror, and metadata reading still works🤖 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