[dancer-users] Don't turn back on warnings that I've turned off

Maxwell Carey mcarey at ucar.edu
Tue Sep 15 22:43:50 BST 2015

What version of Dancer are you using? The behavior changed in v1.3111 when
the import_warnings config setting (import warnings by default) was
replaced by global_warnings (don't import warnings by default). See

I get no warnings for the following app with Dancer 1.3138, using the
default config file:

package MyApp;
use Dancer ':syntax';
no warnings 'uninitialized';

get '/' => sub {
    my $foo;
    print $foo;


On Tue, Sep 15, 2015 at 2:55 PM, Sam Kington <sam at illuminated.co.uk> wrote:

> 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
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150915/ac8da508/attachment.html>

More information about the dancer-users mailing list