]> git.proxmox.com Git - perlmod.git/blame - README.md
README.md update
[perlmod.git] / README.md
CommitLineData
b2ad0247
WB
1perlmod
2=======
3
4This is a rust crate which allows exporting rust modules as perl packages.
5
6The initial use case for this was to help migrating a perl codebase to rust.
7
8This crate can be compared to perl xs, however, it does not expose the complete power of perl, only
9enough to make callable methods. The biggest part is the serde serializer and deserializer,
10providing ways to transfer data between perl and rust.
11
12State of this crate
13===================
14
15This crate is functional and supports a subset perl that the authors consider "sane enough" to work
16with. It may misbehave when faced with dark perl magic (technical term), but should be enough for a
17lot of use cases.
18
19This crate is being used by Proxmox to implement parts of Proxmox VE and Proxmox Mail Gateway, and
20is being maintained as part of these products.
21
22Change Logs
23===========
24
25Since we maintain debian build scripts, see the `debian/changelog` files in `proxmox/` and
26`proxmox-macro/` for their respective changes.
27
28Where to report bugs
29====================
30
31https://bugzilla.proxmox.com
32
33Licensing, linking to libperl and adding more features
34======================================================
35
36The perl license explicitly states that code linking to the perl library for the purpose of merely
37providing subroutines or variables is considered part of its "input", provided it does not change
38the language in any way that would cause it to fail its regression tests. It does not consider its
39"input" to fall under perl's copyright.
40
41In order to avoid confusion about licensing or copyright, this crate does not aim to provide
42complete interoperability, but is meant merely as an alternative to using "xs" for writing bindings
43to rust code.
44
45Features which would allow changing this (other than by obviously unintended behavior (such as
46bugs, raw memory access, etc.)) will not be accepted into this crate and will need to be maintained
47elsewhere.
1f483df2
WB
48
49Pending Changes before 1.0
50==========================
51
52* Don't export non-bootstrap methods anymore, we don't need them.
53* Make some kind of perl-package-generation tool for generating the `.pm`
54 files, we only need to call bootstrap functions after all.
55 (So we may not even need to parse the rust code, rather, just provide a list
56 of perl packages to create...)
57
58Current recommended usage.
59==========================
60
61## "Blessed" objects.
62
63```rust
64#[perlmod::package(name = "My::Pkg", lib = "the_cdylib_name")]
65mod export {
66 use perlmod::{Error, Value};
67
68 // Create the common defaults used for blessed objects with attached magic pointer for rust:
69 perlmod::declare_magic!(Box<MyPkg> : &MyPkg as "My::Pkg");
70
71 struct MyPkg {
72 content: String,
73 }
74
75 impl Drop for MyPkg {
76 fn drop(&mut self) {
77 println!("Dropping blessed MyPkg with content {:?}", self.content);
78 }
79 }
80
81 #[export(raw_return)]
82 fn new(#[raw] class: Value, content: String) -> Result<Value, Error> {
83 Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(MyPkg { content })))
84 }
85
86 #[export]
87 fn call(#[try_from_ref] this: &MyPkg, param: &str) -> Result<(), Error> {
88 println!("Calling magic with content {:?}, with parameter {}", this.content, param);
89 Ok(())
90 }
91}
92```