Generalities first: sure you can, but it may not have the same effect. If the module has an import sub, require does not call it. If the variable is used in a closure, that closure will freeze a default or undef at compile time and never see the change. It's all a matter of how the module is designed.

The MIME::Lite source shows $PARANOID used in the initialization of the file-scoped lexical @Uses at the module's runtime. Paraphrasing:

if (!PARANOID) { push @Uses, $type; }
Now subs will look to the symbol table for the value of a package global but, if I understand this correctly, the @Uses array is populated once when the module's runtime happens. @Uses depends only on the value of $PARANOID at that time. Reetting $PARANOID later has no effect, as you observed. This is independent of use vs. require. It could be made possible to do this:
package MIME::Lite; our $PARANOID = 1; # doesn't work package main; require MIME:Lite;
but that doesn't work because MIME::Lite assigns $PARANOID its default unconditionally (the ||= operator comes to mind here). A redesign of paranoia and type import is needed to get fully featured runtime switching between paranoid and trustful states. So, yes, your problem does appear to be a bug.

The short version is that you must either edit MIME::Lite to set $PARANOID = 1, or else install the extra modules.

It's a different story for your own subs which need the module. If their dependencies are not satisfied until a second round of compilation within runtime, the optimization stage will have to work with much less information, and many foldings will be lost, much unneeded bytecode carried around.

Why do you want to require a module at runtime? If it's for economy, inside a conditional, it may be a false economy.

After Compline,
Zaxo


In reply to (Zaxo) Re x3: MIME::Lite not respecting my decisions by Zaxo
in thread MIME::Lite not respecting my decisions by skazat

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.