Skip to content

fix: parse string interpolations as code via interpolated_fragments()#409

Draft
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-107
Draft

fix: parse string interpolations as code via interpolated_fragments()#409
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-107

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds an interpolated_fragments() method to PPI::Token::Quote::Double, PPI::Token::Quote::Interpolate, and PPI::Token::HereDoc that extracts each interpolated expression from the string and parses it into a PPI::Document::Fragment. This gives callers structured, queryable access to the variables and expressions embedded in interpolating strings — enabling static analysis tools like Perl::Critic to inspect interpolations as parsed code rather than opaque text.

Fixes #107

Changes

  • New private module PPI::Token::_Interpolations with the shared extraction algorithm that handles: simple variables ($x, @x), namespaced variables ($Foo::bar), subscripts ($h{k}, $a[0]), arrow dereferences ($r->{k}), braced forms (${expr}, @{[expr]}), magic variables ($$, $!, $^W), capture variables ($1, $12), and array-index expressions ($#arr)
  • interpolated_fragments() method on Quote::Double, Quote::Interpolate, and HereDoc
  • 71-test file covering all interpolation patterns, escape handling, and cross-class behavior

Test plan

  • All 71 new tests pass across Double, Interpolate, and HereDoc
  • Full existing test suite (53,188 tests across 70 files) passes with no regressions

Generated by Kōan /fix


Quality Report

Changes: 5 files changed, 494 insertions(+), 4 deletions(-)

Code scan: clean

Tests: skipped

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

toddr-bot and others added 2 commits April 27, 2026 03:22
Add test file exercising the new interpolated_fragments() method on
PPI::Token::Quote::Double, PPI::Token::Quote::Interpolate, and
PPI::Token::HereDoc. Tests cover simple variables, arrays, escaped
sigils, hash/array subscripts, arrow derefs, braced forms, complex
expressions, magic variables, namespaced variables, and heredocs.

All assertions are wrapped in $TODO blocks since the method is not
yet implemented.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tions as code

Add interpolated_fragments() method to PPI::Token::Quote::Double,
PPI::Token::Quote::Interpolate, and PPI::Token::HereDoc. Each
interpolation within a double-quoted string is extracted and parsed
into a PPI::Document::Fragment, giving callers structured access to
the variables and expressions embedded in interpolating strings.

The extraction algorithm in the new PPI::Token::_Interpolations private
module handles: simple variables ($x, @x), namespaced variables
($Foo::bar), subscripts ($h{k}, $a[0]), arrow dereferences ($r->{k}),
braced forms (${expr}, @{[expr]}), magic variables ($$, $!, $^W),
capture variables ($1, $12), and array-index expressions ($#arr).

Fixes #107

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.

parse string interpolations as code

1 participant