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.)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.