No description
  • Rust 88%
  • C 4%
  • Perl 3.9%
  • Prolog 3%
  • Makefile 0.7%
  • Other 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Max R. Carrara d85d4ebdd1 perlmod, macro: add #[hash] parameter attribute
Like `#[list]`, `#[hash]` allows us to support subs for which any
number of additional key-value pairs may be passed, which is the same
as having an `;%` at the end of the Perl prototype.

The `ParamsIter` type is added as a helper for pairwise iteration that
makes use of the fact that `ffi::StackIter` is now an
`ExactSizeIterator`, returning an error if the number of values on the
stack is odd on creation. It is then directly passed on to
serde's `MapDeserializer`, mirroring how `#[list]` works with
`SeqDeserializer`.

That way we can support additional Perl APIs without new parameters
breaking the Rust side of the API, just like we can with `#[list]`.

Also document the `#[hash]` parameter and add corresponding tests
along the way.

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
Link: https://lore.proxmox.com/20260730111101.222209-3-m.carrara@proxmox.com
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2026-07-30 18:59:49 +02:00
.cargo move .cargo/config to .cargo/config.toml 2024-06-20 12:25:49 +02:00
perlmod perlmod, macro: add #[hash] parameter attribute 2026-07-30 18:59:49 +02:00
perlmod-bin run make tidy 2026-07-28 14:55:05 +02:00
perlmod-macro perlmod, macro: add #[hash] parameter attribute 2026-07-30 18:59:49 +02:00
testlib perlmod, macro: add #[hash] parameter attribute 2026-07-30 18:59:49 +02:00
testlib-tests perlmod, macro: add #[hash] parameter attribute 2026-07-30 18:59:49 +02:00
.gitignore cleanup 2022-01-07 09:11:41 +01:00
build.sh buildsystem: support dsc and over other improvements from proxmox workspace 2025-05-30 19:04:03 +02:00
Cargo.toml remove old text-output diff-based test 2025-10-08 16:10:46 +02:00
Makefile buildsys: extend make tidy rulest o testlib 2026-07-28 14:56:29 +02:00
README.md update readme 2022-02-28 11:09:07 +01:00
rustfmt.toml rustfmt.toml: update edition to 2024 2025-09-11 12:02:37 +02:00

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(())
    }
}