Skip to content

fix: use named parameter in contents() method#318

Merged
toddr merged 1 commit intocpan-authors:masterfrom
toddr-bot:koan.toddr.bot/fix-contents-fragile-arg
Mar 23, 2026
Merged

fix: use named parameter in contents() method#318
toddr merged 1 commit intocpan-authors:masterfrom
toddr-bot:koan.toddr.bot/fix-contents-fragile-arg

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

@toddr-bot toddr-bot commented Mar 23, 2026

What

Replace $_[1] with the already-extracted $new_contents variable in the contents() setter path.

Why

The method signature at line 1975 already does my ($self, $new_contents) = @_;, but line 2015 bypassed this named parameter and used $_[1] directly (with an XXX comment questioning why). While functionally equivalent for simple strings, $_[1] is an alias to the caller's original argument — fragile if the method signature ever changes.

How

One-line change: $self->{'contents'} = $_[1]$self->{'contents'} = $new_contents. Removed the XXX comment.

Testing

Full test suite passes (1553 tests). The only failure (t/fh-ref-leak.t) is pre-existing and unrelated.

🤖 Generated with Claude Code


Quality Report

Changes: 1 file changed, 1 insertion(+), 2 deletions(-)

Code scan: clean

Tests: skipped

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

The contents() method already extracts $new_contents from @_ at the top
of the sub, but line 2015 used $_[1] directly to assign file contents.
While functionally equivalent for simple strings (which is enforced by
the ref check above), $_[1] is an alias to the caller's argument — a
fragile pattern that bypasses the named parameter and could break if the
method signature ever changes.

Replace $_[1] with $new_contents and remove the XXX comment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@toddr toddr marked this pull request as ready for review March 23, 2026 17:38
@toddr toddr merged commit 07a31a2 into cpan-authors:master Mar 23, 2026
19 checks passed
toddr added a commit that referenced this pull request Mar 23, 2026
…agile-arg

fix: use named parameter in contents() method
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.

2 participants