in reply to PM vs PL
in thread Autovivification with require

I would like to mention a 3rd type of "include": a PMC file which is "compiled" Perl code, see e.g. Module::Compile (or: what's this PMC thingy?). (Edit: also this is of interest Perl v5.6.1 looking for .pmc files)

I don't know whether this project is stil alive but I just confirmed that if a Test.pmc file exists alongside an Test.pm , use Test; will attempt to load Test.pmc first (question: can they be in the different INC dirs?).

Caveat: Because my systems's module compiler (perl -MO=Bytecode,-H -MTest -e1 > Test.pmc) fails with: Can't locate object method "ix" via package "0" , I just touch Test.pmc and surely I get a segfault upon running my script as expected from loading rubbish. The important thing is (i believe) an attempt to load Test.pmc is done. When I delete Test.pmc all runs well, the Test.pm is loaded.

bw, bliako

Replies are listed 'Best First'.
Re^2: PM vs PL - oh there is PMC too!
by Bod (Parson) on Nov 21, 2020 at 14:46 UTC

    The documentation for require does specify that *.pmc takes priority over *.pm files.

    Before require looks for a .pm extension, it will first look for a similar filename with a .pmc extension. If this file is found, it will be loaded in place of any file ending in a .pm extension. This applies to both the explicit require "Foo/Bar.pm"; form and the require Foo::Bar; form.

    The documentation for use doesn't seem to mention *.pmc files.

    Why would one want to pre-compile the code to include?
    My guess is that it gives better performance as the code doesn't need compiling when the script is executed and/or that it provides better security as it is significantly more difficult to look at compiled code and work out what it is doing and how...