Skip to content
New issue

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

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

Already on GitHub? # to your account

don't enable strict or warnings when Moo 3 is requested #40

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
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ my %META = (
'Exporter' => 0,
'Carp' => 0,
'Class::Method::Modifiers' => '1.10', # for RT#80194
'Role::Tiny' => '2.002003',
'Role::Tiny' => '2.003000',
'Sub::Quote' => '2.006006',
'Sub::Defer' => '2.006006',
},
Expand Down
9 changes: 6 additions & 3 deletions lib/Moo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use Moo::_Utils qw(
_load_module
_set_loaded
_unimport_coderefs
VERSION
);
use Carp qw(croak);
BEGIN {
Expand All @@ -26,7 +27,7 @@ BEGIN {
);
}

our $VERSION = '2.005005';
our $VERSION = '3.000000';
$VERSION =~ tr/_//d;

require Moo::sification;
Expand All @@ -43,8 +44,10 @@ sub import {

_set_loaded(caller);

strict->import;
warnings->import;
if (($^H{'Moo::requested_version'} || 0) < 3) {
strict->import;
warnings->import;
}

$class->_install_subs($target, @_);
$class->make_class($target);
Expand Down
10 changes: 8 additions & 2 deletions lib/Moo/Role.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ BEGIN {
);
}

our $VERSION = '2.005005';
our $VERSION = '3.000000';
$VERSION =~ tr/_//d;

require Moo::sification;
Expand All @@ -52,7 +52,13 @@ sub import {
croak "Cannot import Moo::Role into a Moo class";
}
_set_loaded(caller);
goto &Role::Tiny::import;

if (($^H{'Moo::Role::requested_version'} || 0) < 3) {
strict->import;
warnings->import;
}

Role::Tiny->init_role($target);
}

sub _accessor_maker_for {
Expand Down
41 changes: 41 additions & 0 deletions lib/Moo/_Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ BEGIN {

my $module_name_rx = qr/\A(?!\d)\w+(?:::\w+)*\z/;
*_module_name_rx = sub(){$module_name_rx};

*_HINTS_IMPLICIT_LOCAL = ("$]" >= 5.008004) ? sub(){1} : sub(){0};

# goto &UNIVERSAL::VERSION usually works on 5.8, but fails on some ARM
# machines. Seems to always work on 5.10 though.
*_CAN_GOTO_VERSION = ("$]" >= 5.010000) ? sub(){1} : sub(){0};
}

use Exporter ();
Expand Down Expand Up @@ -58,6 +64,7 @@ our @EXPORT_OK = qw(
_linear_isa
_in_global_destruction
_in_global_destruction_code
VERSION
);

my %EXPORTS;
Expand Down Expand Up @@ -285,4 +292,38 @@ if ($Config::Config{useithreads}) {
require Moo::HandleMoose::_TypeMap;
}

sub VERSION {
{
no warnings;
local $@;
if (defined $_[1] && eval { &UNIVERSAL::VERSION; 1}) {
$^H |= 0x20000
unless _HINTS_IMPLICIT_LOCAL;

my $version = $_[1];
$version = "$version"
if ref $version;

$^H{$_[0] . '::requested_version'} = $version;
}
}
if (_CAN_GOTO_VERSION) {
goto &UNIVERSAL::VERSION;
}
else {
my $return;
eval {
$return = &UNIVERSAL::VERSION;
1;
} or do {
my $e = $@ || 'Zombie error';
my $oldloc = sprintf ' at %s line %d.', __FILE__, __LINE__ - 4;
my $newloc = sprintf ' at %s line %d.', (caller(1))[1,2];
$e =~ s{\Q$oldloc\E\n.*}{$newloc\n}s;
die $e;
};
return $return;
}
}

1;