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.)


In reply to require in script breaks module by chrstphrchvz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.