Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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:

Brothers

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 warnings.pm and ship it with my module?

I need some advice on this.

Comment on using modules with 'no warnings' in perl 5.005
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 "warnings.pm" 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 liz (Monsignor) on Jul 29, 2003 at 08:08 UTC
    Creating a mock warnings.pm 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 warnings.pm 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{'warnings.pm'} = 'I do not really exist'; } } #BEGIN

    Liz

      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{'warnings.pm'}=''; }; }

      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?

        Liz
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 warnings.pm, 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2014-12-26 06:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (166 votes), past polls