Fix ::identifier bareword parsing and jcpan cpan script#322
Merged
Conversation
Two fixes: 1. Parser fix for ::identifier barewords (ParsePrimary.java): - In Perl, `::foo` without parens is a bareword string '::foo' - Only `::foo()` with parens is a function call to main::foo - PerlOnJava was incorrectly treating all `::identifier` as main::identifier - This broke Mo module which uses patterns like `$M.$_.::e` - Now: `::foo()` -> main::foo(), `::foo` -> '::foo' string 2. Added cpan script to sync config (config.yaml): - The jcpan wrapper requires src/main/perl/bin/cpan - Added import from perl5/cpan/CPAN/scripts/cpan - Fixes 'Unable to read file' error on fresh checkouts Mo test improvement: 14/28 failing -> 6/28 failing (133/144 subtests pass) Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
- Added src/main/perl/bin/cpan to git (required by jcpan) - Updated .gitignore to allow src/main/perl/bin/ directory Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
The hash was being cleared before iterating over the RHS list.
For self-referential assignments like `%h = (new_stuff, %h)`,
this caused the hash contents to be lost.
Fix: Materialize the entire RHS list into a temporary array before
clearing the hash, similar to how tied hashes are handled.
This fixes Mo module BUILD support - Mo uses:
%e = (extends => sub{...}, has => sub{...}, %e)
to merge feature-provided exports with defaults.
Mo test improvement: 6/28 failing -> 1/28 failing (143/144 subtests pass)
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <noreply@cognition.ai>
The previous fix always treated `::foo` (without parens) as a bareword string.
But in Perl, `::foo` without parens calls `main::foo` if the sub exists at
compile time, and only becomes a bareword string if no such sub exists.
Now checks GlobalVariable.getGlobalCodeRef(fullSubName).getDefinedBoolean()
to determine if the sub exists, matching Perl's behavior.
This fixes tests that use `::is ::exception { }` patterns where `is` and
`exception` are imported subs that should be called.
Mo still works: `$M.$_.::e` correctly produces '::e' bareword because
no `main::e` sub exists at that point.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <noreply@cognition.ai>
- Phase 24: Fix ::identifier bareword parsing - Phase 25: Fix self-referential hash assignment Mo: 27/28 passing (99.3%) Moo: 62/71 passing (87%), 768/829 subtests (93%) Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
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
Two fixes for Mo module support and jcpan functionality:
1. Parser fix for ::identifier barewords
In Perl,
::foowithout parentheses is a bareword that stringifies to'::foo', while::foo()with parens is a function call tomain::foo. PerlOnJava was incorrectly treating all::identifierpatterns asmain::identifier.This broke the Mo module which uses patterns like
$M.$_.::eto dynamically build package names.Before:
After:
2. Added cpan script to sync config
The jcpan wrapper requires
src/main/perl/bin/cpanto exist. Added import fromperl5/cpan/CPAN/scripts/cpanto config.yaml so fresh checkouts work correctly.Test Results
Mo module tests:
Unit tests: All passing
Test Plan
make)./jperl -e 'print $x.::e'outputs::e(bareword)./jperl -e 'sub foo {"X"} print ::foo()'outputsX(function call)./jcpan --helpworksGenerated with Devin