Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

MIME::Lite not respecting my decisions

by skazat (Chaplain)
on Mar 04, 2002 at 20:34 UTC ( [id://149206]=perlquestion: print w/replies, xml ) Need Help??

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

If I do this:

require MIME::Lite; $MIME::Lite::PARANOID = 1;

because in the docs I read this:

$MIME::Lite::PARANOID If true, we won't attempt to use MIME::Base64, MIME::QuotedPri +nt, or MIME::Types, even if they're available. Default is false.

Because I'm concerned that I don't have MIME::Base64, MIME::QuotedPrint and friends, and I still get an error that says:

Can't locate MIME/Types.pm in @INC (@INC contains: ../ . ../../ ./ ./M +OJO /usr/lib/perl5/5.6.0/i386-linux /usr/lib/perl5/5.6.0 /usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/site_perl/5.6 +.0 /usr/lib/perl5/site_perl) at (eval 27) line 3.

What is one to do? As far as I know, I'm using the module correctly, is there some difference in its behavior if I use it or require it?

-justin simoni
!skazat!

Replies are listed 'Best First'.
Re: MIME::Lite not respecting my decisions
by rjray (Chaplain) on Mar 04, 2002 at 22:04 UTC

    It looks like the MIME::Lite module is still trying to read in the MIME::Types code, despite your setting of that flag. It could be that MIME::Lite needs the code in some other capacity, or it could be an oversight on the part of the MIME::Lite developer.

    What I recommend you do is send e-mail to the maintainer of MIME::Lite, to point out this problem. But in the short-term, just to get your own work back on a forward-moving track, I recommend installing MIME::Types from CPAN.

    --rjray

Re: MIME::Lite not respecting my decisions
by Zaxo (Archbishop) on Mar 04, 2002 at 22:50 UTC
    use MIME::Lite;require happens at runtime, use at compile time so you get the early bindings and import.

    Update, corrected module name, thanks jlongino

    After Compline,
    Zaxo

      So there's no way to change the value of a public and documented variable if I use 'require'? I find that very hard to believe. In the module, it's not exported, I wonder why the author set it up this way, instead of providing a method for this?

      weird

       

      -justin simoni
      !skazat!

        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

Re: MIME::Lite not respecting my decisions
by Ido (Hermit) on Mar 04, 2002 at 22:12 UTC
    I can't get to see the error message on my machine(I tried removing the other Mime's..) But I think you might have to set the flag BEFORE requiring the module.
    $MIME::Lite::PARANOID = 1; require MIME::Lite;
    (ViM: dd->p;) I don't know if it will work, nor I can't test it, but I think it worth a try.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://149206]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found