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.