fix: update tell position after PRINT/WRITE/PRINTF operations#199
Open
Koan-Bot wants to merge 4 commits intocpanel:masterfrom
Open
fix: update tell position after PRINT/WRITE/PRINTF operations#199Koan-Bot wants to merge 4 commits intocpanel:masterfrom
Koan-Bot wants to merge 4 commits intocpanel:masterfrom
Conversation
Contributor
|
view failure from CI |
Contributor
|
@Koan-Bot rebase |
72a6b9e to
b2dc908
Compare
Contributor
Author
Fix: say() test replaced with explicit $\ testRoot cause: Changes:
The |
atoomic
approved these changes
Feb 23, 2026
PRINT never updated $self->{'tell'} after writing, so tell() always
returned the pre-write position. This caused incorrect behavior when
mixing writes and reads on the same filehandle, or when checking
position after writes.
Since PRINTF and WRITE both delegate to PRINT, the fix applies to
all write operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tied PRINT now respects $\ when set explicitly by the caller (e.g. local $\ = "\n"; print $fh ...). Note: say() does NOT set $\ for tied handles — Perl handles its newline at the C level after PRINT returns. This is a known limitation of Perl's tied filehandle system. Replaced the say() test with an explicit $\ test that validates the actual behavior. Added documentation comment about the limitation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b2dc908 to
21abbcd
Compare
In non-append modes (+<, >, +>), print/printf now writes at the current tell position using substr overwrite, matching real Perl behavior. Append mode (>>, +>>) still always writes at end. Changes: - Add 'append' flag to TIEHANDLE, set from open mode (>> / +>>) and sysopen O_APPEND flag - PRINT uses substr to overwrite at tell position for non-append - Handles $, (output field separator) between list elements - Pads with null bytes if tell is past end of contents Tests: 7 new subtests covering +< seek+print overwrite, >> append after seek, interleaved read+write, and > mode overwrite. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Updated: PRINT now writes at the tell position instead of always appending. What was broken: In What changed:
7 new tests in
|
Writing "XY" at position 3 of "ABCDEFGH" replaces D(3) and E(4), leaving F(5)G(6)H(7) intact → "ABCXYFGH", not "ABCXYEGH". The E at position 4 was overwritten by Y, so position 5 is F. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
PRINTnever updated$self->{'tell'}after writing, sotell()always returned the pre-write positionPRINTFandWRITEboth delegate toPRINT, the fix applies to all write operationsChanges
lib/Test/MockFile/FileHandle.pm: Added$self->{'tell'} = length($self->{'data'}->{'contents'})after write inPRINTt/write_tell.t: 7 test blocks coveringprint,printf,syswrite, read+write mode, append mode, undef handling, andsayTest plan
t/write_tell.tvalidates tell position after all write operationst/writeline.tandt/seek.tremain green🤖 Generated with Claude Code