fix: wrap flag lookup tables in eval for Windows portability#55
Draft
fix: wrap flag lookup tables in eval for Windows portability#55
Conversation
The stty() setting loop and show_me_the_crap() display function both had 30+ individual if/elsif statements for flag handling — each one a copy-paste of the same bit-manipulation pattern. Replace with hash lookup tables (%CFLAGS, %IFLAGS, %LFLAGS, %OFLAGS, %CC_NAMES) and ordered arrays (@CFLAG_DISPLAY, @LFLAG_DISPLAY, @IFLAG_DISPLAY). Benefits: - Net reduction of 26 lines despite adding table definitions - Adding a new flag is now one table entry instead of two code blocks - Aliases (hup→HUPCL, crterase→ECHOE) are just extra table entries - Single source of truth for which flags exist and what they map to Character size (cs5-cs8) and baud rate (ispeed/ospeed) handling remain explicit since they have special mask-and-set semantics. All 139 tests pass unchanged — exact output format preserved. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
**Summary:** Added missing `[IGNCR,'igncr']` entry to `@IFLAG_DISPLAY` array in `lib/IO/Stty.pm`. The `igncr` flag was present in the `%IFLAGS` setter table but was accidentally omitted from the display table, causing `-a` output to not show the igncr flag. This is exactly the bug (#50) that the refactor was meant to prevent — the display list and setter list got out of sync.
The refactored flag tables (CFLAGS, IFLAGS, etc.) evaluated POSIX
termios constants at file scope. On Windows, Perl's POSIX module
exports these symbols but they die when called, breaking module
loading entirely. The old if/elsif code only evaluated them at
runtime inside function bodies, so this was a regression.
Wrap the table initialization in BEGIN { eval { ... } } — same
pattern used for baud rate constants. On Windows, hashes stay
empty and the module loads fine; stty() fails at runtime if called,
which matches the pre-refactor behavior.
Also fix version mismatch from rebase (0.07 → 0.08 to match main).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Apr 10, 2026
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
Wraps the refactored flag lookup tables (
%CFLAGS,%IFLAGS,%LFLAGS,%OFLAGS,@*_DISPLAY) inBEGIN { eval { ... } }so the module loads on Windows.Why
PR #52 moved POSIX termios constants from runtime evaluation (inside function bodies) to file-scope hash initialization. On Windows, Perl's POSIX module exports these symbols but they die when called — breaking
use IO::Sttyentirely. All CI test files failed to compile.How
Same pattern as the existing
%BAUD_RATESinitialization:BEGIN { eval { ... } }. On platforms without termios, the hashes stay empty and the module loads fine. Callingstty()will fail at runtime, matching pre-refactor behavior.Also fixes version mismatch from rebase (0.07 → 0.08).
Testing
Builds on #52
🤖 Generated with Claude Code
Quality Report
Changes: 5 files changed, 83 insertions(+), 274 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: 1 issue(s)
Generated by Kōan post-mission quality pipeline