Skip to content

WIP: Add Moo object system support#319

Merged
fglock merged 12 commits into
masterfrom
feature/moo-support
Mar 15, 2026
Merged

WIP: Add Moo object system support#319
fglock merged 12 commits into
masterfrom
feature/moo-support

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Mar 14, 2026

Summary

This PR adds support for the Moo object system in PerlOnJava.

Completed

  • Phase 1: Replaced Java-based Carp with Perl's full Carp.pm

    • Deleted Carp.java (only implemented basic functions)
    • Imported Carp.pm and Carp/Heavy.pm from perl5/dist/Carp
    • Updated DBI.java to use WarnDie directly
  • Phase 2: Fixed string interpolation bug with @;

    • "\$@;" now correctly produces "$@;" instead of "$"
    • Added non-identifier characters to isNonInterpolatingCharacter()

In Progress

  • Phase 3: Debugging Method::Generate::Constructor->new() returning undef
    • BUILDARGS works correctly
    • bless appears to return undef in bootstrap context
    • Root cause still under investigation

Pending

  • Phase 4: Fix parser bug with x => syntax (treated as string repetition operator instead of autoquoted bareword)
  • Phase 5: End-to-end Moo testing

Test Plan

  • Unit tests pass (156 tests)
  • use Moo; loads successfully
  • Basic Moo class with attributes works
  • has x => (is => 'ro') syntax parses correctly

Design Document

See dev/design/moo_support.md for full details and progress tracking.

Generated with Devin

fglock and others added 12 commits March 14, 2026 21:47
Phase 1 - Replace Java-based Carp with Perl Carp.pm:
- Delete Carp.java (only had basic functions)
- Import full Carp.pm and Carp/Heavy.pm from perl5/dist/Carp
- Update DBI.java to use WarnDie directly instead of Carp

Phase 2 - Fix string interpolation bug with @;:
- Added non-identifier characters to isNonInterpolatingCharacter()
- Fixes: "\$@;" now correctly produces "$@;" instead of "$"

Phase 3 - In progress:
- Investigating Method::Generate::Constructor->new() returning undef
- BUILDARGS works correctly, bless appears to return undef
- Root cause still under investigation

Pending:
- Phase 4: Fix parser bug with x => syntax (treated as string rep operator)
- Phase 5: End-to-end Moo testing

See dev/design/moo_support.md for full details.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
This commit addresses two issues preventing Moo from working correctly:

1. Parser fix: `x =>` is now correctly autoquoted as a bareword
   - In ListParser.looksLikeEmptyList(), `x` followed by `=>` was being
     treated as an infix operator, causing empty list detection
   - Added check: when `x` is followed by `=>`, don't treat it as empty list
   - In Parser.parseExpression(), `x=` followed by `>` now breaks parsing
     to allow `x` to be treated as a bareword

2. Tailcall trampoline for method calls (goto &$coderef fix)
   - Added TAILCALL handling in Dereference.java for method calls
   - When RuntimeCode.callCached() returns a TAILCALL marker, the
     trampoline loop now processes it at the call site
   - Made EmitSubroutine.emitBlockDispatcher() package-visible

These fixes allow Moo's `has x => (is => "ro")` syntax to work correctly.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
- Phase 1: Carp.pm replacement ✓
- Phase 2: @; string interpolation fix ✓
- Phase 3: goto &$coderef JVM fix ✓
- Phase 4: x => parser fix ✓
- Phase 5: End-to-end testing ✓

Added next steps for future enhancements:
- Test Moo::Role support
- Test more attribute options
- Performance testing
- Add Moo tests to test suite
- Document in README

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
The jcpan wrapper was still referencing the obsolete jcpan.pl which was
removed in commit 7606d38. Updated to use src/main/perl/bin/cpan like
jcpan.bat does.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
The Storable.java deserializeFromYAML() method was using the default
SnakeYAML limit of 3MB, causing "retrieve failed" errors when reading
large CPAN metadata files.

Added setCodePointLimit(50 * 1024 * 1024) to match YAMLPP.java.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Added current objectives:
1. Moo tests run inside jcpan
2. Moo tests pass (40/71 currently passing)

Added test failure analysis and Phase 6 (jcpan/Storable fixes).

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Moo is not a goal in itself - it is a test case for CPAN integration.
All Moo tests must pass to validate that:
- jcpan can install CPAN modules correctly
- jcpan can run module tests
- Complex pure-Perl CPAN modules work in PerlOnJava

Current status: 40/71 tests passing (BLOCKING)

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
The parser was incorrectly treating @{*{expr}} as hash subscript
on @* (the special variable). Now it correctly parses it as array
dereference of glob dereference: @{ *{expr} }

This fix consists of two parts:
1. In IdentifierParser.parseComplexIdentifierInner: When * is followed
   by {, return null to force fallback to expression parsing
2. In Variable.parseBracedVariable: Only unwrap the * operator when
   the operand is a simple IdentifierNode (for ${*F} -> $F), not when
   it's a complex expression like *{$x}

This enables Moo's extends functionality which uses the pattern:
  @{*{_getglob("${target}::ISA")}} = @_

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
1. IdentifierParser: Only apply *{ glob dereference fix when inside braces
   - @{*{expr}} parses as array of glob deref (correct)
   - @*{key} parses as hash slice on @* (correct, no longer broken)

2. StringSegmentParser: Fix @; interpolation without breaking $/
   - Added isValidArrayVariableStart() to check valid array var chars
   - @; is NOT interpolated (correct, not a valid array variable)
   - $/ IS interpolated (correct, valid scalar variable)
   - Reverted overly aggressive isNonInterpolatingCharacter changes

These fixes resolve the test regressions:
- op/chop.t: 137/148 (was 135, matches master)
- op/concat2.t: 3/4 (was 2, matches master)
- op/magic.t: 170/208 (was 169, matches master)
- re/regexp.t: 1786/2210 (was 1709, matches master)

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Return 1 to indicate reference-counted stack behavior. This is
appropriate for PerlOnJava since Java GC keeps objects alive as
long as they are referenced, similar to Perl RC stack builds.

This fix enables op/array.t tests 136-199 to run (they were being
skipped or causing OOM due to the unimplemented function returning
undef). Test results improved from 116 to 175 passing tests.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Enhanced comments to prevent accidental reversion of critical fixes:

- IdentifierParser.java: Explain glob dereference fix for Moo extends
- Variable.java: Document when *{expr} should remain as glob dereference
- StringSegmentParser.java: Explain @; vs $/ interpolation distinction
- Parser.java/ListParser.java: Document x => autoquoting for Moo hashes
- Internals.java: Explain why stack_refcounted must return 1 for tests

All comments reference the specific tests or features that would break
if the code were reverted.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
- Added Issue 5: Parser bug with @{*{expr}} glob dereference (FIXED)
- Added Issue 6: Internals::stack_refcounted() not implemented (FIXED)
- Added Phase 7: Fix parser for @{*{expr}} enabling Moo extends
- Added Phase 8: Implement stack_refcounted (op/array.t 116->175)
- Updated test results table showing all baselines met
- Added inheritance example with extends keyword
- Updated commit list with all recent commits
- Changed status to TESTING (verify Moo extends works)

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit ae14dc4 into master Mar 15, 2026
2 checks passed
@fglock fglock deleted the feature/moo-support branch March 15, 2026 09:18
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.

1 participant