Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

using modules with 'no warnings' in perl 5.005

by busunsl (Vicar)
on Jul 29, 2003 at 07:40 UTC ( #278753=perlquestion: print w/replies, xml ) Need Help??

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


I have the following problem:

I'm writing a Tk backend for CPANPLUS and use a module that uses 'no warnings' in the middle of its code.

Since CPANPLUS runs on Perl 5.005_03 I'd like to have my backend running on perl 5.005_03 but that doesn't support warnings.

So what am I to do? Forget using the module that needs warnings?
Mock up a and ship it with my module?

I need some advice on this.

  • Comment on using modules with 'no warnings' in perl 5.005

Replies are listed 'Best First'.
Re: using modules with 'no warnings' in perl 5.005
by liz (Monsignor) on Jul 29, 2003 at 08:08 UTC
    Creating a mock and putting it on CPAN, was actually discussed at the p5p BOF at YAPC::Europe. Unfortunately (and this is my opinion) it was deciced to not do this (yet) because of the uncertainty of all the ramifications, particularly involving version numbers (you don't want CPAN installing perl 5.8.0 because some module author added as a prerequisite, for instance).

    However, you can mock it like this:

    BEGIN { unless (eval "require warnings;") { eval <<EOD; sub warnings::import {}; sub warnings::unimport {}; EOD $INC{''} = 'I do not really exist'; } } #BEGIN


      Everybody is too eval(string) happy for my tastes ;)
      BEGIN { eval { require warnings; 1 } or do { no strict 'refs'; *warnings::import = *warnings::unimport = sub{}; $INC{''}=''; }; }

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        Ok, fair enough.

        One question though: the 1 in line 4 of your code seems superfluous to me. A successful 'require warnings' should return a true value anyway, no?

Re: using modules with 'no warnings' in perl 5.005
by Corion (Pope) on Jul 29, 2003 at 07:48 UTC

    I would take the following approach, faking a "" without creating a file like that :

    eval "use warnings;"; if ($@) { eval q{ package warnings; sub import {}; sub unimport {}; }; };
    You could try to also do some funky stuff with $^W, but as warnings is a lexical pragma, it's best not to go there :-)
    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Re: using modules with 'no warnings' in perl 5.005
by bart (Canon) on Jul 29, 2003 at 11:42 UTC
    What module would that be?

    If this is for suppression for runtime warnings, as I think it is, my thought would be to just localize $^W, making it false. For example:

    { local $^W; # disable runtime warnings for this block # For example: $str = join "#", 'A', undef, 'B'; }

    If a module depends on, it might also include some other stuff that only works on 5.6 and up. You never know.

    If, however, the above patch actually does what is wanted, and the module works on 5.005, and if this is an official module on CPAN, I would like to have steps taken to remove this dependency from the official distribution.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://278753]
Approved by Corion
Front-paged by arthas
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2020-09-21 12:47 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (125 votes). Check out past polls.