in reply to Re^2: How to call Encode::decode from Perl XS
in thread How to call Encode::decode from Perl XS

Yes and no. If you want a module to automatically load another module from XS, and not import all functions/methods, this is a cleaner way to do so. Of course you can croak/fail/die/barf/puke when a user tries to invoke something that he/she did not explicitely load, but as Encode is a CORE module I see no harm in hiding the require from XS and making the underlying module DWIM more.

I agree that this is a grey/gray area and opinions may well differ if which case I think you should agree to disagree.

XS is a different world and pulling the right strings is sometimes extremely hard compared to how easy perl made it in the language level itself.


Enjoy, Have FUN! H.Merijn
  • Comment on Re^3: How to call Encode::decode from Perl XS

Replies are listed 'Best First'.
Re^4: How to call Encode::decode from Perl XS
by ikegami (Patriarch) on May 09, 2011 at 15:43 UTC

    If you want a module to automatically load another module from XS, and not import all functions/methods,

    Not importing can be done from Perl too. It's not an advantage of XS. In Perl, not importing is done by using

    use Exporter qw( );
    or
    require Exporter;
    instead of
    use Exporter;

    As for automaticallydynamically loading a module, a need hasn't been mentioned.

    Update: Added first two sentences to clear up confusion mentioned in private message.

      I don't believe I do need to dynamically load Encode from XS so long as using it from DBD::ODBC's ODBC.pm makes decode usable in XS via call_xx.

        Once a module is loaded, it's loaded for the whole interpreter. If you don't import decode, you'll need to qualify the function name (Encode::decode(...)).