Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dev/import-perl5/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ imports:
target: perl5_t/version
type: directory

# I18N::Langinfo - locale information (XS implementation in Java)
- source: perl5/ext/I18N-Langinfo/Langinfo.pm
target: src/main/perl/lib/I18N/Langinfo.pm

# From core distribution
- source: perl5/dist/Attribute-Handlers/lib/Attribute/Handlers.pm
target: src/main/perl/lib/Attribute/Handlers.pm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ public static RuntimeList executePerlAST(Node ast,
globalSymbolTable.addVariable("@_", "our", null);
globalSymbolTable.addVariable("wantarray", "", null);

// Inherit $^H (strictOptions) from the caller's scope so BEGIN blocks
// can see and modify the enclosing scope's compile-time hints
if (savedCurrentScope != null) {
globalSymbolTable.setStrictOptions(savedCurrentScope.getStrictOptions());
}

EmitterContext ctx = new EmitterContext(
new JavaClassInfo(),
globalSymbolTable.snapShot(),
Expand Down Expand Up @@ -274,8 +280,10 @@ public static RuntimeList executePerlAST(Node ast,

return executeCode(runtimeCode, ctx, false, contextType);
} finally {
// Restore the caller's scope
// Propagate $^H changes back to the caller's scope so subsequent
// code in the same lexical block sees the updated hints
if (savedCurrentScope != null) {
savedCurrentScope.setStrictOptions(ctx.symbolTable.getStrictOptions());
SpecialBlockParser.setCurrentScope(savedCurrentScope);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/perlonjava/core/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class Configuration {
* Automatically populated by Gradle/Maven during build.
* DO NOT EDIT MANUALLY - this value is replaced at build time.
*/
public static final String gitCommitId = "1d09334fe";
public static final String gitCommitId = "217705588";

/**
* Git commit date of the build (ISO format: YYYY-MM-DD).
Expand Down
351 changes: 351 additions & 0 deletions src/main/java/org/perlonjava/runtime/perlmodule/I18NLanginfo.java

Large diffs are not rendered by default.

82 changes: 47 additions & 35 deletions src/main/java/org/perlonjava/runtime/perlmodule/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.perlonjava.runtime.runtimetypes.GlobalVariable.getGlobalVariable;
import static org.perlonjava.runtime.runtimetypes.RuntimeScalarCache.*;
import static org.perlonjava.runtime.runtimetypes.RuntimeScalarType.DOUBLE;
import static org.perlonjava.runtime.runtimetypes.RuntimeScalarType.UNDEF;
import static org.perlonjava.runtime.runtimetypes.RuntimeScalarType.VSTRING;

// TODO - create test cases
Expand Down Expand Up @@ -87,8 +88,13 @@ private static RuntimeList parseInternal(RuntimeArray args, int ctx, boolean for
// Track whether the original input was a v-string
boolean isVString = false;

// Handle undef - treat as version 0 (Perl behavior)
if (versionStr.type == UNDEF) {
version = "0";
originalVersionStr = new RuntimeScalar("0");
}
// Handle VSTRING type (bare v-strings like v1.2.3)
if (versionStr.type == VSTRING) {
else if (versionStr.type == VSTRING) {
isVString = true;
// Convert VSTRING to dotted format
String vstringValue = versionStr.value.toString();
Expand All @@ -102,47 +108,53 @@ private static RuntimeList parseInternal(RuntimeArray args, int ctx, boolean for
} else {
version = versionStr.toString().trim();

if (version.isEmpty()) {
throw new PerlCompilerException("Invalid version format (version required)");
}
// Handle literal string "undef" - treat as version 0 (Perl behavior)
if (version.equals("undef")) {
version = "0";
originalVersionStr = new RuntimeScalar("0");
} else {
if (version.isEmpty()) {
throw new PerlCompilerException("Invalid version format (version required)");
}

// Check if original starts with 'v'
isVString = version.startsWith("v");
// Check if original starts with 'v'
isVString = version.startsWith("v");

// Validate version format - check for multiple underscores
int underscoreCount = 0;
for (char c : version.toCharArray()) {
if (c == '_') underscoreCount++;
}
if (underscoreCount > 1) {
throw new PerlCompilerException("Invalid version format (multiple underscores)");
}
// Validate version format - check for multiple underscores
int underscoreCount = 0;
for (char c : version.toCharArray()) {
if (c == '_') underscoreCount++;
}
if (underscoreCount > 1) {
throw new PerlCompilerException("Invalid version format (multiple underscores)");
}

// Validate version format - must contain at least one digit
// and be a valid version pattern (digits, dots, underscores, optional v prefix)
String checkVersion = isVString ? version.substring(1) : version;
checkVersion = checkVersion.replace("_", "");
// Validate version format - must contain at least one digit
// and be a valid version pattern (digits, dots, underscores, optional v prefix)
String checkVersion = isVString ? version.substring(1) : version;
checkVersion = checkVersion.replace("_", "");

// Version must start with a digit and only contain digits and dots
// (after removing v prefix and underscores)
if (!checkVersion.matches("\\d+(\\.\\d+)*")) {
throw new PerlCompilerException("Invalid version format (non-numeric data)");
}
// Version must start with a digit and only contain digits and dots
// (after removing v prefix and underscores)
if (!checkVersion.matches("\\d+(\\.\\d+)*")) {
throw new PerlCompilerException("Invalid version format (non-numeric data)");
}

if (versionStr.type == DOUBLE) {
// Format with enough precision but strip trailing zeros
version = String.format("%.6f", versionStr.getDouble());
// Remove trailing zeros after decimal point
if (version.contains(".")) {
version = version.replaceAll("0+$", "");
// Remove trailing dot if all decimals were zeros (e.g., "1." -> "1")
if (version.endsWith(".")) {
version = version.substring(0, version.length() - 1);
if (versionStr.type == DOUBLE) {
// Format with enough precision but strip trailing zeros
version = String.format("%.6f", versionStr.getDouble());
// Remove trailing zeros after decimal point
if (version.contains(".")) {
version = version.replaceAll("0+$", "");
// Remove trailing dot if all decimals were zeros (e.g., "1." -> "1")
if (version.endsWith(".")) {
version = version.substring(0, version.length() - 1);
}
}
originalVersionStr = new RuntimeScalar(version);
} else {
originalVersionStr = versionStr;
}
originalVersionStr = new RuntimeScalar(version);
} else {
originalVersionStr = versionStr;
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/perlonjava/runtime/perlmodule/Warnings.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ public static boolean warningExists(String category) {
* @return A RuntimeList containing a boolean value.
*/
public static RuntimeList enabled(RuntimeArray args, int ctx) {
if (args.size() < 1 || args.size() > 2) {
if (args.size() > 2) {
throw new IllegalStateException("Bad number of arguments for warnings::enabled()");
}
String category = args.get(0).toString();
String category;
if (args.size() < 1) {
// No category specified - check if warnings are enabled for calling package
// Use "all" as the category to check general warning state
category = "all";
} else {
category = args.get(0).toString();
}
boolean isEnabled = warningManager.isWarningEnabled(category);
return new RuntimeScalar(isEnabled).getList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,14 @@ public RuntimeScalar scalarDeref() {
yield newScalar;
}
case REFERENCE -> (RuntimeScalar) value;
case REGEX -> {
// Dereferencing a Regexp (qr//) returns its stringified form
// In Perl, ${qr/foo/} returns "(?^:foo)"
RuntimeScalar result = new RuntimeScalar();
result.type = RuntimeScalarType.STRING;
result.value = this.value.toString();
yield result;
}
case GLOB -> {
// Dereferencing a glob as scalar returns the scalar slot
// e.g., ${*Foo::VERSION} or ${$glob} where $glob is a glob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ public ScalarSpecialVariable(Id variableId, int position) {
*/
@Override
void vivify() {
if (variableId == Id.INPUT_LINE_NUMBER || variableId == Id.HINTS) {
if (variableId == Id.INPUT_LINE_NUMBER) {
if (lvalue == null) {
lvalue = new RuntimeScalar(0);
}
return;
}
// HINTS doesn't need lvalue - it always reads/writes from the symbol table
if (variableId == Id.HINTS) {
return;
}
throw new PerlCompilerException("Modification of a read-only value attempted");
}

Expand All @@ -85,19 +89,14 @@ public RuntimeScalar set(RuntimeScalar value) {
}
if (variableId == Id.HINTS) {
int hints = value.getInt();
// Update the symbol table's strict options
// Update the symbol table's strict options directly
// No need to store in lvalue since reading always uses the symbol table
ScopedSymbolTable symbolTable = SpecialBlockParser.getCurrentScope();
if (symbolTable != null) {
// Clear all strict options and set the new ones
// The hints value contains the strict flags directly
symbolTable.setStrictOptions(hints);
}
// Also store in lvalue for reading back
vivify();
lvalue.set(hints);
this.type = lvalue.type;
this.value = lvalue.value;
return lvalue;
// Return a scalar with the hints value
return getScalarInt(hints);
}
return super.set(value);
}
Expand Down Expand Up @@ -212,11 +211,8 @@ public RuntimeScalar getValueAsScalar() {
yield scalarUndef;
}
case HINTS -> {
// $^H - Return stored lvalue first (preserves custom hint bits like 0x04000000)
// Only fall back to symbol table strict options if no lvalue stored
if (lvalue != null) {
yield lvalue;
}
// $^H - Always read from the current scope's symbol table
// This ensures lexical scoping - each scope has its own $^H value
ScopedSymbolTable symbolTable = SpecialBlockParser.getCurrentScope();
if (symbolTable != null) {
yield getScalarInt(symbolTable.getStrictOptions());
Expand Down
Loading
Loading