Skip to content

Optionally disable importing warnings into caller package #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Moo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ sub import {
my $class = shift;
_set_loaded(caller);

my $no_warnings = grep /:no_warnings/, @_;

strict->import;
warnings->import;
warnings->import unless $no_warnings;

if ($INC{'Role/Tiny.pm'} and Role::Tiny->is_role($target)) {
croak "Cannot import Moo into a role";
Expand Down
34 changes: 34 additions & 0 deletions t/moo.t
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,38 @@ is(MyClass5->foo, 'foo with around', 'method modifier');
'can extend Moo class with overridden new';
}

{
no strict 'refs';
no warnings 'redefine';

my $import = 0;

local *{"warnings::import"} = sub { $import++ };

eval {
package MyClass8;
require Moo;
Moo->import;
};

::is $import, 1, "use Moo imports warnings";
}

{
no strict 'refs';
no warnings 'redefine';

my $import = 0;

local *{"warnings::import"} = sub { $import++ };

eval {
package MyClass9;
require Moo;
Moo->import( qw(:no_warnings) );
};

::is $import, 0, "use Moo :no_warnings";
}

done_testing;