Git Product home page Git Product logo

perlmod-rs's Introduction

perlmod

This is a rust crate which allows exporting rust modules as perl packages.

The initial use case for this was to help migrating a perl codebase to rust.

This crate can be compared to perl xs, however, it does not expose the complete power of perl, only enough to make callable methods. The biggest part is the serde serializer and deserializer, providing ways to transfer data between perl and rust.

State of this crate

This crate is functional and supports a subset perl that the authors consider "sane enough" to work with. It may misbehave when faced with dark perl magic (technical term), but should be enough for a lot of use cases.

This crate is being used by Proxmox to implement parts of Proxmox VE and Proxmox Mail Gateway, and is being maintained as part of these products.

Change Logs

Since we maintain debian build scripts, see the debian/changelog files in proxmox/ and proxmox-macro/ for their respective changes.

Where to report bugs

https://bugzilla.proxmox.com

Licensing, linking to libperl and adding more features

The perl license explicitly states that code linking to the perl library for the purpose of merely providing subroutines or variables is considered part of its "input", provided it does not change the language in any way that would cause it to fail its regression tests. It does not consider its "input" to fall under perl's copyright.

In order to avoid confusion about licensing or copyright, this crate does not aim to provide complete interoperability, but is meant merely as an alternative to using "xs" for writing bindings to rust code.

Features which would allow changing this (other than by obviously unintended behavior (such as bugs, raw memory access, etc.)) will not be accepted into this crate and will need to be maintained elsewhere.

Pending Changes before 1.0

  • Make some kind of perl-package-generation tool for generating the .pm files, we only need to call bootstrap functions after all. (So we may not even need to parse the rust code, rather, just provide a list of perl packages to create...)

Current recommended usage.

"Blessed" objects.

#[perlmod::package(name = "My::Pkg")]
mod export {
    use perlmod::{Error, Value};

    // Create the common defaults used for blessed objects with attached magic pointer for rust:
    perlmod::declare_magic!(Box<MyPkg> : &MyPkg as "My::Pkg");

    struct MyPkg {
        content: String,
    }

    impl Drop for MyPkg {
        fn drop(&mut self) {
            println!("Dropping blessed MyPkg with content {:?}", self.content);
        }
    }

    #[export(raw_return)]
    fn new(#[raw] class: Value, content: String) -> Result<Value, Error> {
        Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(MyPkg { content })))
    }

    #[export]
    fn call(#[try_from_ref] this: &MyPkg, param: &str) -> Result<(), Error> {
        println!("Calling magic with content {:?}, with parameter {}", this.content, param);
        Ok(())
    }
}

perlmod-rs's People

Contributors

blub avatar foxmox avatar fabian-gruenbichler avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.