Skip to content

fix: read WHILE_MAX at runtime instead of compile-time#340

Draft
Koan-Bot wants to merge 1 commit intoabw:masterfrom
atoomic:koan.atoomic/fix-while-max-runtime
Draft

fix: read WHILE_MAX at runtime instead of compile-time#340
Koan-Bot wants to merge 1 commit intoabw:masterfrom
atoomic:koan.atoomic/fix-while-max-runtime

Conversation

@Koan-Bot
Copy link
Contributor

@Koan-Bot Koan-Bot commented Mar 8, 2026

What

Generate code that reads $Template::Directive::WHILE_MAX at runtime instead of interpolating it as a literal number at compile-time.

Why

The while() method in Template::Directive interpolates $WHILE_MAX directly into the generated Perl code as a literal. This bakes the value in at template compilation time, so:

  • Changing $Template::Directive::WHILE_MAX after compilation has no effect
  • Compiled-to-disk templates (via COMPILE_DIR/COMPILE_EXT) permanently use whatever value was set when first compiled

How

Replace $WHILE_MAX interpolation in the heredoc with escaped \$Template::Directive::WHILE_MAX references, so the generated code reads the package variable at execution time.

Testing

  • 6 new tests in t/while_max_runtime.t: verify WHILE_MAX changes take effect without recompilation, including compiled-to-disk templates
  • Full test suite passes (2967 tests, 108 files)

🤖 Generated with Claude Code

The $WHILE_MAX value was interpolated as a literal number into the
generated Perl code in Template::Directive::while(). This meant that
changing $Template::Directive::WHILE_MAX after template compilation
had no effect, and compiled-to-disk templates permanently baked in
whatever value was set when they were first compiled.

Generate code that references $Template::Directive::WHILE_MAX directly,
so the value is always read at execution time.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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