http://www.perlmonks.org?node_id=632199


in reply to Was a module use'd or require'd?

I keep re-reading this. and I cannot, for the life of me, see what value you can derive from knowing that a module was required rather than used?

Despite your explanations elsewhere, I would suggest that is it dangerous, and even unethical(in the most minor, trivial sense of that term) for you to make that determination.

What the f*** is he prattling on about?I hear the time-sync'd chorus emote.

Well, think of it like the cold war. And the continuous escalation that was the primary result of it.

If you can determine some difference between the overall effect of my module by determining whether it was required or used, then maybe there is some action I can take within my module to make that same determination and so alter that effect. But then, if you can detect it, and I can alter it, maybe there is some mechanism that will allow me to alter it but not allow you to detect it.

Of course, it's inevitable, that if I start taking action dependant upon whether you can detect whether I was required or used, that you are going to look for a method of subverting my method of detection whether I was required or used.

But if my module renames perl5x.dll and substitutes itself in that namespace, then I can intercept your calls to pp_require() and, falsely, report failure to require, but the go on to install myself anyway.

Alternatively, I could override require so that it was always actioned at BEGIN time, and always called the module import routine with a default value of :all.

That may not work identically to use in all cases, but it would stop Ovid from telling the difference between use and require in 87.243789100000000000001% of cases. And hey, that got to be worth the effort :)


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Was a module use'd or require'd?
by Ovid (Cardinal) on Aug 13, 2007 at 13:04 UTC

    This is merely for a debugging module to offer hints for what's going on under the hood. That's all. It's for developers only, not intended for code to rely on and it has heavy caveats about what the output is and why it is intended as a crutch, but should not be relied upon.

    Cheers,
    Ovid

    New address of my CGI Course.

      This is merely for a debugging module to offer hints for what's going on under the hood.

      I understand that, but I still can't see the purpose. That is, to derive any benefit from a hint that a module was required rather than used, when debugging or otherwise, there would have to be some practical, effective difference in the way the module performed in those two scenarios. If there is no difference, then there is no benefit to knowing.

      And if there is a difference, then eventually someone is going to find a way of either:

      • exploiting that difference to provide some additional functionality.
      • detecting that difference so as to counter the effects of it in the way their module performs.

      Since I couldn't (and still cannot) think of any difference in the way a module would perform dependant upon whether it was required or used, I couldn't see the benefit of jumping through hoops to make the determination.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.