fix: Term::ReadLine - add missing methods, honour PERL_RL, fix ReadKey prototype#658
Merged
fix: Term::ReadLine - add missing methods, honour PERL_RL, fix ReadKey prototype#658
Conversation
…y prototype
Five distinct bugs in the Term::ReadLine / Term::ReadKey Java backends:
Bug 1 – PERL_RL env var ignored
TermReadLine used super("Term::ReadLine") which set %INC at JVM startup,
preventing the companion Perl file from running and $ENV{PERL_RL}='Perl'
from ever taking effect. Fix:
- Add src/main/perl/lib/Term/ReadLine.pm (copy of the dist stub) so
Term::ReadLine::Stub, ::TermCap and ::Tk packages are available.
- Switch to super("Term::ReadLine", false) so %INC is not pre-set and
the Perl file is executed normally on `use Term::ReadLine`.
- In newReadLine(), check %ENV{PERL_RL}; when it contains "Perl", require
Term::ReadLine::Perl from ~/.perlonjava/lib and delegate via
InheritanceResolver / RuntimeCode.apply (with try/catch fallback).
Bug 2 – GetHistory / SetHistory never registered
Features hash advertised getHistory/setHistory=1, but no Perl-callable
methods existed. Added static getHistoryList / setHistoryList + registered
them as GetHistory / SetHistory. Also registered AddHistory as a
camelCase alias for addhistory.
Bug 3 – ornaments method missing
Added a no-op ornaments() stub so $term->ornaments(0) doesn't die.
Added ornaments=1 to the features hash.
Bug 4 – newTTY method missing
Added a no-op newTTY() stub (JVM cannot rewire streams via Perl globs,
but the method must exist). Added newTTY=1 to the features hash.
Bug 5 – readline ignores preput argument; feature absent
readline($prompt, $preput) second arg was silently dropped. Now the
preput text is appended to the displayed prompt as "[text]", and an
empty reply from the user adopts the preput value. Added preput=1 to
the features hash.
Bonus fixes:
- appName was read from args[0] (the class name) instead of args[1];
Attribs->{appname} now reflects the name passed to new().
- args[2]/[3] corrected for the optional IN/OUT filehandle slots.
- Term::ReadKey::ReadKey prototype changed from ";$" to ";$$" so that
readline.pm's two-arg call ReadKey(0, $fh) no longer fails with
"Too many arguments" at compile time.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.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
Fixes six bugs found while investigating
./jcpan -t Term::ReadLine::Perl.Bug 1 —
PERL_RLenv var ignoredTermReadLine.initialize()pre-set%INC{"Term/ReadLine.pm"}at JVM startup, so scripts settingBEGIN{ $ENV{PERL_RL}='Perl' }could never load the CPAN implementation. Fixed by:src/main/perl/lib/Term/ReadLine.pm(the standard dist stub) soTerm::ReadLine::Stub,::TermCap, and::Tkpackages are available to the CPAN module.super("Term::ReadLine", false)so%INCis not pre-set and the Perl file runs normally onuse Term::ReadLine.newReadLine(), reading%ENV{PERL_RL}at call-time; when it saysPerl, requiringTerm::ReadLine::Perland delegating viaInheritanceResolver/RuntimeCode.apply(with fallback to the Java impl on failure).Bug 2 —
GetHistory/SetHistorymethods not registeredFeatures hash claimed
getHistory=1andsetHistory=1but neitherGetHistorynorSetHistorywas callable. AddedgetHistoryList/setHistoryListstatic methods and registered them. Also registeredAddHistory(camelCase alias).Bug 3 —
ornamentsmethod missing$term->ornaments(0)died. Added a no-op stub; addedornaments=1to the features hash.Bug 4 —
newTTYmethod missing$term->newTTY(\*IN, \*OUT)died. Added a no-op stub (stream rewiring is not possible via Perl globs on the JVM); addednewTTY=1to the features hash.Bug 5 —
readlineignorespreputargument; feature absent$term->readline($prompt, "exit")silently dropped the second argument. Now displays it as[text]in the prompt and adopts it when the user presses Enter on an empty line. Addedpreput=1to the features hash.Bonus fixes
appNamewas read fromargs[0](the class name) instead ofargs[1];Attribs->{appname}now reflects the name passed tonew().Term::ReadKey::ReadKeyprototype changed from";$"to";$$"soreadline.pm's two-arg callReadKey(0, $fh)no longer fails with "Too many arguments" at compile time.Test plan
makepasses (all unit tests green)./jperl /tmp/test_readline_full.pl— all six method tests pass, features complete,PERL_RL=PerlreturnsTerm::ReadLine::PerlAUTOMATED_TESTING=1 ./jperl test.pl— emits1..0 # skip(correct automated-test behaviour)echo "exit" | ./jperl test.pl --no-print— runs interactively, exits cleanly on EOFGenerated with Devin