develooper Front page | perl.perl5.porters | Postings from July 2003

Re: Warnings.pm ?

Thread Previous | Thread Next
From:
Stas Bekman
Date:
July 30, 2003 01:44
Subject:
Re: Warnings.pm ?
Message ID:
3F278529.3000902@stason.org
Elizabeth Mattijsen wrote:
> I was thinking of putting the following code (courtesy PodMaster on 
> PerlMonks):
> 
> BEGIN {
>     eval { require warnings } or do {
>         no strict 'refs';
>         *warnings::import = *warnings::unimport = sub{};
>         $INC{'warnings.pm'}='';
>     }
> } #BEGIN
[...]

I thought the conclusion (at the p5p meeting) was not to provide any hollow 
misleading implementations. The reason: it doesn't do anything and will 
falsely lead some people (who won't look at the source code) to think that 
they have warnings enabled, when in fact they aren't.

Let each developer provide their own workaround if they have to support < 5.6. 
In that case they know exactly what they are doing. So for example if they 
don't care that the warnings won't be on, they can add anywhere in their code 
the code similar to yours. I suppose this can be documented somewhere.

For example in Apache::Test we have an infrastructure to "support" older 
perls, and we know that warnings won't do anything:

package Apache::Test5005compat;

use strict;
use Symbol ();
use File::Basename;
use File::Path;

$Apache::Test5005compat::VERSION = '0.01';

my %compat_files = (
      'lib/warnings.pm' => \&warnings_pm,
);

sub import {
     if ($] >= 5.006) {
         #make sure old compat stubs dont wipe out installed versions
         unlink for keys %compat_files;
         return;
     }

     eval { require File::Spec::Functions; } or
       die "this is only Perl $], you need to install File-Spec from CPAN";

     my $min_version = 0.82;
     unless ($File::Spec::VERSION >= $min_version) {
         die "you need to install File-Spec-$min_version or higher from CPAN";
     }

     while (my($file, $sub) = each %compat_files) {
         $sub->($file);
     }
}

sub open_file {
     my $file = shift;

     unless (-d 'lib') {
         $file = "Apache-Test/$file";
     }

     my $dir = dirname $file;

     unless (-d $dir) {
         mkpath([$dir], 0, 0755);
     }

     my $fh = Symbol::gensym();
     print "creating $file\n";
     open $fh, ">$file" or die "open $file: $!";

     return $fh;
}

sub warnings_pm {
     return if eval { require warnings };

     my $fh = open_file(shift);

     print $fh <<'EOF';
package warnings;

sub import {}

1;
EOF

     close $fh;
}

1;





__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About