Hi,

At $WORK we have a codebase that’s currently running under perl 5.14.2 that we 
want to move to perl 5.20.3. (Can’t use 5.22 because, via another module that 
we use, we use Coro, which blows up spectacularly if you’re running a version 
of Perl that the author of Coro disapproves of.)

The codebase makes regular use of smartmatch (albeit only in the “match a 
variable against this array” sense). This produces warnings in modern Perls, so 
my plan was to extend our standard “enable all pragmas according to house 
policy” module to disable experimental::smartmatch warnings, under Perls that 
are known to warn about this but still implement it in the same way. That gives 
us a year or two to get rid of it once p5p decide what they’re going to do with 
smartmatch.

Unfortunately, Dancer turns the warnings back on. Even if you’d previously 
disabled them.

I can understand saying “if you haven’t enabled warnings, you really should 
have, so Dancer is going to enable them for you”. I can also understand people 
saying “use Dancer” and expecting warnings to be enabled, so they don’t have to 
explicitly say “use warnings”. That’s fine.

But if I’ve explicitly enabled most but not all warnings, Dancer shouldn’t 
trample all over that.

As it is, I have to write this to avoid warnings:

#!/usr/bin/env perl

use 5.20.1;
no warnings 'experimental::smartmatch';
no warnings 'uninitialized';

use Dancer qw(:syntax);

no warnings 'experimental::smartmatch';
no warnings 'uninitialized';

my $foo = shift;
given ($foo) {
    when ('foo') {
        say "This is foo, the King of variable names";
    }
    when (['bar', 'baz']) {
        say "A lesser pretender $_";
    }
    default {
        say "$_ is dead to me";
    }
}

This is a toy example just to make the point: rather than that one use Dancer 
statement I could have a whole bunch of use statements, and Dancer could have 
been pulled in by some other module, possibly not even something I imported 
directly.

Now, I could get rid of one line in the example above by saying

no warnings::anywhere ‘uninitialized’;

as that would turn that warning off globally, but warnings::everywhere doesn’t 
work with compile-time pragmas.

Is there a way to find out whether the calling package has enabled warnings, 
and if so don’t enable all of them again? Because that would be ideal.

Sam
-- 
Website: http://www.illuminated.co.uk/

_______________________________________________
dancer-users mailing list
[email protected]
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users

Reply via email to