Skip to content

Commit

Permalink
Don't futz with $^W. Import warnings and remove import_warnings conf …
Browse files Browse the repository at this point in the history
…setting.

Use warnings->import when importing Dancer2 to ensure any code using it has
the warnings pragma enabled (just like strict and utf8).

L<perllexwarn> states ".. using $^W to either disable or enable blocks of
code is fundamentally flawed.". Also see Matt Trout's comments in PerlDancer#427.

Remove the import_config setting and its trigger that mucks with $^W and purge
it from the POD. If anyone really wants to set $^W, they can add it to their
app or psgi file and be in control of the results.
  • Loading branch information
veryrusty committed Sep 8, 2013
1 parent 144e09a commit 049e0d8
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/Dancer2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ sub import {
my ( $caller, $script ) = caller;

strict->import;
warnings->import;
utf8->import;

my @final_args;
Expand Down
5 changes: 0 additions & 5 deletions lib/Dancer2/Config.pod
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,6 @@ C<template> keyword. Check C<Dancer2> manpage for details.
If true, C<config> will return an object instead of a hash reference. See
L<Dancer2::Config::Object> for more information.

=head3 import_warnings (boolean, default: enabled)

If true, or not present, C<use warnings> will be in effect in scripts in which
you import C<Dancer2>. Set to a false value to disable this.

=head3 startup_info (boolean)

If set to true, prints a banner at the server start with information such as
Expand Down
8 changes: 4 additions & 4 deletions lib/Dancer2/Cookbook.pod
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ route specification, whose value is made available through C<params>
- more on that later.

Note that you don't need to use the C<strict> and C<warnings> pragma, they are
already loaded by Dancer2. (If you don't want the C<warnings> pragma (which can
lead to undesired warnings about use of undef values, for example), then set the
L<import_warnings|Dancer2::Config/import_warnings> setting to a false value.

already loaded by Dancer2.

If you I<really> do not want the C<warnings> pragma (for example, due to an
undesired warning about use of undef values), add a C<no warnings> pragma to
the appropriate block in your module or psgi file.

=head2 Starting a Dancer2 project

Expand Down
4 changes: 0 additions & 4 deletions lib/Dancer2/Core/Role/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,6 @@ sub _build_config_triggers {

# TODO route_cache
return {
import_warnings => sub {
my ( $self, $value ) = @_;
$^W = $value ? 1 : 0;
},
traces => sub {
my ( $self, $traces ) = @_;
require Carp;
Expand Down
1 change: 0 additions & 1 deletion lib/Dancer2/Core/Runner.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ sub default_config {
views => ( $ENV{DANCER_VIEWS}
|| path( $self->config_location, 'views' ) ),
appdir => $self->location,
import_warnings => 1,
};
}

Expand Down

0 comments on commit 049e0d8

Please sign in to comment.