Skip to content

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Jan 14, 2026

Problem

ExifTool commands (exiftool -list and -listw) failed with "Undefined subroutine" errors when JPERL_LARGECODE=refactor was enabled.

Root Cause

When Exporter imports a forward-declared subroutine, the imported placeholder wasn't configured to resolve via the exporting package's AUTOLOAD mechanism, breaking standard Perl semantics.

Solution

Made three key changes:

  1. Exporter.exportToLevel: Handle empty caller() by defaulting to 'main'
  2. Exporter.importFunction: Annotate imported forward-declaration placeholders with sourcePackage field
  3. RuntimeCode.apply: Check sourcePackage first when attempting AUTOLOAD resolution

This matches Perl's behavior where imported forward declarations resolve via the original package's AUTOLOAD.

Testing

  • Added regression test: src/test/resources/unit/exiftool_exporter_autoload.t
  • Test passes in system Perl, jperl (normal mode), and jperl (refactor mode)
  • All existing unit tests pass
  • ExifTool -list and -listw now get past the GetAllTags/GetWritableTags errors

Files Changed

  • src/main/java/org/perlonjava/perlmodule/Exporter.java
  • src/main/java/org/perlonjava/runtime/RuntimeCode.java
  • src/test/resources/unit/exiftool_exporter_autoload.t (new)

This commit fixes the issue where ExifTool commands (exiftool -list and
-listw) failed with 'Undefined subroutine' errors when JPERL_LARGECODE=refactor
was enabled.

Problem:
When Exporter imports a forward-declared subroutine (e.g., 'sub GetAllTags;'),
the imported placeholder in the calling package wasn't configured to resolve
via the exporting package's AUTOLOAD mechanism, breaking standard Perl semantics.

Solution:
1. Exporter.exportToLevel: Handle empty caller() by defaulting to 'main'
2. Exporter.importFunction: Annotate imported forward-declaration placeholders
   with sourcePackage field pointing to the exporting package
3. RuntimeCode.apply (both overloads): Check sourcePackage first when attempting
   AUTOLOAD resolution for undefined subs

This matches Perl's behavior where imported forward declarations resolve via
the original package's AUTOLOAD.

Test:
- Added regression test: src/test/resources/unit/exiftool_exporter_autoload.t
- Test passes in Perl, jperl (normal), and jperl (refactor mode)
- All existing unit tests pass
- ExifTool -list/-listw now get past the GetAllTags/GetWritableTags errors
@fglock fglock merged commit 2a3cc86 into master Jan 14, 2026
2 checks passed
@fglock fglock deleted the fix/exiftool-missing-subs branch January 14, 2026 11:53
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.

2 participants