- * Note: Configuration values can be set using the Configure.pl script. - * For example, to set the Perl version, you can run: + * Configuration values are managed using the Configure.pl script: *
- * ./Configure.pl -D perlVersion=v5.40.0 + * ./Configure.pl -D version=5.43.0 # Update version everywhere + * ./Configure.pl # Show current configuration *
- * To update the jar version across all files in the repository: + * This will update the version constant in this class and replace all + * occurrences of perlonjava-X.Y.Z.jar throughout the repository. *
- * ./Configure.pl -D jarVersion=3.0.1 - *
- * This will update both constants in this configuration class and replace - * all occurrences of perlonjava-3.0.0.jar with perlonjava-3.0.1.jar. + * Git commit information (gitCommitId, gitCommitDate) is automatically + * injected by the build system (Gradle or Maven) before compilation. + * Do not edit these values manually - they will be overwritten on each build. */ public final class Configuration { - // Perl version information - public static final String perlVersion = "v5.42.0"; - public static final String jarVersion = "3.0.0"; + /** + * Unified version number for PerlOnJava. + * This version is used for both the JAR artifact and Perl compatibility version. + * Updated via: ./Configure.pl -D version=X.Y.Z + */ + public static final String version = "5.42.0"; + + /** + * Git commit ID (short hash) of the build. + * Automatically populated by Gradle/Maven during build. + * DO NOT EDIT MANUALLY - this value is replaced at build time. + */ + public static final String gitCommitId = "610d942c5"; + + /** + * Git commit date of the build (ISO format: YYYY-MM-DD). + * Automatically populated by Gradle/Maven during build. + * DO NOT EDIT MANUALLY - this value is replaced at build time. + */ + public static final String gitCommitDate = "2026-03-10"; // Prevent instantiation private Configuration() { } + /** + * Returns the version for use with "use VERSION" feature bundles. + * For version 5.42.0, returns ":5.42" + */ public static String getPerlVersionBundle() { - return ":" + perlVersion.substring(1, perlVersion.lastIndexOf('.')); + int lastDot = version.lastIndexOf('.'); + return ":" + version.substring(0, lastDot); } + /** + * Returns the version string without 'v' prefix. + * Since version is already stored without 'v', this returns it directly. + */ public static String getPerlVersionNoV() { - return perlVersion.startsWith("v") ? perlVersion.substring(1) : perlVersion; + return version.startsWith("v") ? version.substring(1) : version; } + /** + * Returns the version in old Perl $] format (e.g., "5.042000" for 5.42.0). + */ public static String getPerlVersionOld() { String versionNoV = getPerlVersionNoV(); String[] parts = versionNoV.split("\\."); @@ -55,7 +84,7 @@ public static String getPerlVersionOld() { /** * Returns the Perl version as a vstring RuntimeScalar. - * For example, v5.42.0 becomes a vstring with bytes \u0005*\u0000 + * For example, 5.42.0 becomes a vstring with bytes \u0005*\u0000 * where each version component is represented as a character. * * @return RuntimeScalar with type VSTRING containing the version diff --git a/src/main/java/org/perlonjava/frontend/parser/StatementParser.java b/src/main/java/org/perlonjava/frontend/parser/StatementParser.java index dda9d18e1..cf76594f2 100644 --- a/src/main/java/org/perlonjava/frontend/parser/StatementParser.java +++ b/src/main/java/org/perlonjava/frontend/parser/StatementParser.java @@ -501,7 +501,7 @@ public static Node parseUseDeclaration(Parser parser, LexerToken token) { if (packageName == null) { parser.ctx.logDebug("use version: check Perl version"); VersionHelper.compareVersion( - new RuntimeScalar(Configuration.perlVersion), + new RuntimeScalar(Configuration.version), versionScalar, "Perl"); diff --git a/src/main/java/org/perlonjava/runtime/operators/ModuleOperators.java b/src/main/java/org/perlonjava/runtime/operators/ModuleOperators.java index 44bbb1925..094b1caa8 100644 --- a/src/main/java/org/perlonjava/runtime/operators/ModuleOperators.java +++ b/src/main/java/org/perlonjava/runtime/operators/ModuleOperators.java @@ -708,7 +708,7 @@ public static RuntimeScalar require(RuntimeScalar runtimeScalar) { // ===== CASE 1: Version checking ===== if (runtimeScalar.type == RuntimeScalarType.INTEGER || runtimeScalar.type == RuntimeScalarType.DOUBLE || runtimeScalar.type == RuntimeScalarType.VSTRING || runtimeScalar.type == RuntimeScalarType.BOOLEAN) { // `require VERSION` - use version comparison - String currentVersionStr = Configuration.perlVersion; + String currentVersionStr = Configuration.version; String displayVersion = VersionHelper.getDisplayVersionForRequire(runtimeScalar); String normalizedRequired = VersionHelper.normalizeVersionForRequireComparison(runtimeScalar); diff --git a/src/main/java/org/perlonjava/runtime/operators/VersionHelper.java b/src/main/java/org/perlonjava/runtime/operators/VersionHelper.java index 99716c858..8b809a469 100644 --- a/src/main/java/org/perlonjava/runtime/operators/VersionHelper.java +++ b/src/main/java/org/perlonjava/runtime/operators/VersionHelper.java @@ -9,30 +9,40 @@ public class VersionHelper { // Helper method to normalize version to a comparable decimal format for require private static String normalizeVersionToDecimalForRequire(String version) { - if (version.startsWith("v")) { - // v-string like v5.42.0 -> 5.042000, v5.5.630 -> 5.005630 - String[] parts = version.substring(1).split("\\."); - if (parts.length > 0) { - StringBuilder normalized = new StringBuilder(parts[0]); - if (parts.length > 1) { - normalized.append("."); - for (int i = 1; i < parts.length; i++) { - // Pad each component to 3 digits with leading zeros - String part = parts[i]; - while (part.length() < 3) { - part = "0" + part; // Pad with leading zeros - } - normalized.append(part); - } - } else { - // Handle cases like "v5" -> "5.000000" - normalized.append(".000000"); + // Remove v prefix if present + String v = version.startsWith("v") ? version.substring(1) : version; + + // Handle underscore versions like 5.005_63 -> 5.00563 + v = v.replace("_", ""); + + // Check if this is a dot-separated version like 5.42.0 (more than one dot) + String[] parts = v.split("\\."); + if (parts.length > 2 || (parts.length == 2 && version.startsWith("v"))) { + // Multi-component version like 5.42.0 or v5.42.0 -> 5.042000 + StringBuilder normalized = new StringBuilder(parts[0]); + normalized.append("."); + for (int i = 1; i < parts.length; i++) { + // Pad each component to 3 digits with leading zeros + String part = parts[i]; + while (part.length() < 3) { + part = "0" + part; // Pad with leading zeros } - return normalized.toString(); + normalized.append(part); + } + // Ensure at least 6 decimal digits for consistency + String decimalPart = normalized.substring(normalized.indexOf(".") + 1); + while (decimalPart.length() < 6) { + normalized.append("0"); + decimalPart = normalized.substring(normalized.indexOf(".") + 1); } + return normalized.toString(); + } else if (parts.length == 1) { + // Single number like "10" -> "10.000000" + return v + ".000000"; } - // Handle underscore versions like 5.005_63 -> 5.005063 - return version.replace("_", ""); + + // Already in decimal format like 5.042000 + return v; } // Helper method to normalize version for require comparison diff --git a/src/main/perl/lib/DBI.pm b/src/main/perl/lib/DBI.pm index 4c8550924..e60afd62a 100644 --- a/src/main/perl/lib/DBI.pm +++ b/src/main/perl/lib/DBI.pm @@ -10,7 +10,7 @@ XSLoader::load( 'DBI' ); # Example: # -# java -cp "h2-2.2.224.jar:target/perlonjava-3.0.0.jar" org.perlonjava.app.cli.Main dbi.pl +# java -cp "h2-2.2.224.jar:target/perlonjava-5.42.0.jar" org.perlonjava.app.cli.Main dbi.pl # # # Connect to H2 database # my $dbh = DBI->connect(