Skip to content

An implementation of the Perl programming language designed to run on the Java platform

License

Notifications You must be signed in to change notification settings

fglock/PerlOnJava

Repository files navigation

PerlOnJava: A Perl Distribution for the JVM

PerlOnJava provides a Perl distribution designed to run natively on the Java Virtual Machine (JVM). It allows Perl scripts to integrate seamlessly with Java-based ecosystems while offering familiar tools and modules for Perl development.

The JAR package features a variety of Perl modules, such as DBI (with JDBC support), HTTP::Tiny, JSON, YAML, File::Find, and Data::Dumper. Users can also add their own database JDBC drivers, making it a flexible solution for cross-platform Perl applications.

Table of Contents

  1. Introduction
  2. Why PerlOnJava
  3. Target Audience
  4. Quick Start
  5. Features and Limitations
  6. Build Instructions
  7. Running with Docker
  8. Running the JAR File
  9. Debugging Tools
  10. Architecture
  11. Porting Modules
  12. Milestones
  13. Community and Support
  14. License
  15. Additional Resources

Introduction

PerlOnJava bridges the gap between Perl and Java by providing a platform that compiles Perl scripts into Java bytecode, making them executable on the JVM. By leveraging this distribution, developers can run familiar Perl code while accessing Java's ecosystem of libraries and tools. This project aims to bring the strengths of Perl to modern JVM environments while supporting a growing list of core modules and pragmas.

Need help? Check out our Community and Support section.

What This Project Is

  • A JVM-Native Perl Implementation: Runs Perl code directly on the Java Virtual Machine
  • A Bridge to Java Ecosystems: Enables Perl scripts to interact with Java libraries and frameworks
  • A Cross-Platform Solution: Provides consistent Perl behavior across different operating systems via JVM
  • A Modern Integration Tool: Allows Perl codebases to participate in Java-based enterprise environments

Target Audience

  • Java Developers with Perl Knowledge: Provides a method for integrating Perl scripts into Java applications.
  • Compiler and Language Enthusiasts: Offers insights into translating high-level languages into JVM bytecode.
  • Experimenters and Tinkerers: A tool for experimenting with language interoperability.

Quick Start

Get started quickly with PerlOnJava. For a complete list of capabilities, see our Feature Matrix.

  1. Build the project (detailed instructions):

    mvn clean package
  2. Run a simple Perl script:

Linux/Mac
./jperl -E 'say "Hello World"'
Windows
jperl -E "say 'Hello World'"
  1. Use Perl in your Java application:

    import javax.script.*;
    
    public class TestPerl {
       public static void main(String[] args) throws Exception {
          ScriptEngineManager manager = new ScriptEngineManager();
          ScriptEngine engine = manager.getEngineByName("perl");
          engine.eval("print 'Hello from Java-integrated Perl!\n'");
       }
    }
  2. Connect to a database:

    use DBI;
    my $dbh = DBI->connect("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1");
    $dbh->do("CREATE TABLE test (id INT, name VARCHAR(50))");
    $dbh->do("INSERT INTO test VALUES (1, 'Hello World')");

Running the JAR File

  1. Show Instructions:
Linux/Mac
./jperl --help
Windows
jperl --help
  1. Execute Something:
Linux/Mac
./jperl -E 'print 123'
Windows
jperl -E "print 123"

Debugging Tools

  1. Execute Emitting Debug Information:
Linux/Mac
./jperl --debug -E 'print 123'
Windows
jperl --debug -E "print 123"
  1. Compile Only; Can Be Combined with --debug:
Linux/Mac
./jperl -c -E 'print 123'
./jperl --debug -c -E 'print 123'
Windows
jperl -c -E "print 123"
jperl --debug -c -E "print 123"
  1. Execute and Emit Disassembled ASM Code:
Linux/Mac
./jperl --disassemble -E 'print 123'
Windows
jperl --disassemble -E "print 123"
  1. Run the Lexer Only:
Linux/Mac
./jperl --tokenize -E 'print 123'
Windows
jperl --tokenize -E "print 123"
  1. Run the Parser Only:
Linux/Mac
./jperl --parse -E 'print 123'
Windows
jperl --parse -E "print 123"

License

This project is licensed under the Perl Artistic License 2.0 - see the LICENSE file for details.

Java CI with Maven