http://qs321.pair.com?node_id=1230821


in reply to Re: require in script breaks module
in thread require in script breaks module

Thanks for the reply and suggesting possible workarounds.

Peeking inside the .ph file on my machines, it's mostly just more requires. So unfortunately neither do 'sys/ioctl.ph' nor delete $INC{'sys/ioctl.ph'}; require 'sys/ioctl.ph' alone yield any improvement.

I ended up moving the require to where it would be run once during the module's import, only nested in an eval so that any error is saved to a package variable. Then, when the feature requiring ioctl is used, any error will be croaked; and tests can check the package variable to know whether to skip. Here's the implementation: https://github.com/chrstphrchvz/perl-tcl-ptk/commit/75abce83f7

Maybe there is something more elaborate that resists the effects of require appearing in "user" code, but because this particular feature in the module is due for replacement (likely by something written in C/XS), I've opted for something low-effort and less invasive as it were.