[dancer-users] Don't turn back on warnings that I've turned off
Sam Kington
sam at illuminated.co.uk
Tue Sep 15 23:05:10 BST 2015
> 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;
> };
I get this with Dancer and Dancer2, and I should have been clearer.
There are two things that are in violent conflict here.
The first is the instinct to turn pragmas on as soon as possible. For all of its many, many faults, Perl::Critic is right to say that you should say use strict as soon as possible, so muscle memory pretty much requires that you start typing this for every new script or module:
use strict;
use warnings;
no warnings ‘uninitialized’;
no warnings ‘experimental::smartmatch’;
If this was a standalone script I’d have added a shebang at the start, and possibly a use lib, but otherwise it’s the same idea: start off with a blank slate, say what you want to happen system-wide, then pull in various CPAN and/or private modules, then write your own code.
(At $WORK we have a module called our::way which does all of this for us, so you just say use our::way at the start and it enables strictures, most warnings, UTF8 mode etc.)
What’s in conflict with this approach is that if I say use Dancer - or I import a module, directly or indirectly, that says use Dancer qw(:syntax) or something - then all of my warnings are reset. So I have to say no warnings ‘experimental::smartmatch’ again.
It’s not just Dancer that does this - I believe Moose and Moo also do it. But it’s still annoying and rude.
Sam
--
Website: http://www.illuminated.co.uk/
More information about the dancer-users
mailing list