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

chrstphrchvz has asked for the wisdom of the Perl Monks concerning the following question:

Howdy Monks,

I have a test that I would like to skip if a requisite .ph file is not available, so I considered using:

eval { require 'sys/ioctl.ph' }; # skip if $@ contains # "Can't locate 'sys/ioctl.ph' in @INC (did you run h2ph?)"

However, doing require 'sys/ioctl.ph' from the test script "breaks" the module.

Here is a simplified equivalent:

funnybusiness.pm:

package funnybusiness; use warnings; use strict; sub s1 { require 'sys/ioctl.ph'; print FIONREAD() . "\n"; # should print some number } 1;

test.pl:

use warnings; use strict; use funnybusiness; #require 'sys/ioctl.ph'; funnybusiness::s1;

Assuming sys/ioctl.ph is available, running test.pl prints the value of FIONREAD in sys/ioctl.h. But uncommenting the require statement in test.pl causes an Undefined subroutine &funnybusiness::FIONREAD error.

I can prevent the error by having funnybusiness.pm use main::FIONREAD() instead (edit: that breaks normal code that doesn't have the require statement). But I would like to understand why the require statement in the script is "breaking" the module: whether there's some bad assumption that funnybusiness.pm makes about what FIONREAD() can mean, or if the script should somehow know better than to do a require that might be done by the module, or if this behavior might be a bug/limitation/feature, etc.

(Actual module for anyone curious:

The module makes use of AUTOLOAD, meaning I get something more wacky than a Undefined subroutine error.)