Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: module with conditional xs code

by tobyink (Canon)
on Mar 18, 2020 at 23:23 UTC ( #11114448=note: print w/replies, xml ) Need Help??


in reply to module with conditional xs code

You could look at match::simple and match::simple::XS.

The way it works is match::simple::XS provides a function called match. Users load match::simple. When match::simple is first loaded, it attempts to load match::simple::XS and import the match function. If it fails, it does a stringy eval on a pure Perl implementation of match. It exports match to the user.

End users just do use match::simple; if they have match::simple::XS installed, they get the XS implementation automatically.

Replies are listed 'Best First'.
Re^2: module with conditional xs code
by navalned (Beadle) on Mar 19, 2020 at 02:37 UTC

    I think this will work for me. It looks like I will still have to have two separate modules, but it will make things easier than they are now. Plus I was introduced to two cool modules to play with.

    Thanks!

Re^2: module with conditional xs code
by salva (Canon) on Mar 20, 2020 at 00:51 UTC
    Indeed, I did something quite similar for Math::Vector::Real and Math::Vector::Real::XS, but instead of creating the pure Perl methods on demand on the main module, they are just regular functions always defined and the XS module overwrites them with its own versions when loaded.

    The advantage of that approach is that it allows me to implement only a subset of the functions on the XS side.

      Thanks for the input. I'll take a look at these. Sounds like it may be a better approach.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11114448]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-05-28 23:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?