diff --git a/Makefile.PL b/Makefile.PL index c9e177c..4bb22a8 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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', }, diff --git a/lib/Moo.pm b/lib/Moo.pm index 06f45e0..00b3ad7 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -14,6 +14,7 @@ use Moo::_Utils qw( _load_module _set_loaded _unimport_coderefs + VERSION ); use Carp qw(croak); BEGIN { @@ -26,7 +27,7 @@ BEGIN { ); } -our $VERSION = '2.005005'; +our $VERSION = '3.000000'; $VERSION =~ tr/_//d; require Moo::sification; @@ -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); diff --git a/lib/Moo/Role.pm b/lib/Moo/Role.pm index c15d572..e6f39d0 100644 --- a/lib/Moo/Role.pm +++ b/lib/Moo/Role.pm @@ -27,7 +27,7 @@ BEGIN { ); } -our $VERSION = '2.005005'; +our $VERSION = '3.000000'; $VERSION =~ tr/_//d; require Moo::sification; @@ -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 { diff --git a/lib/Moo/_Utils.pm b/lib/Moo/_Utils.pm index d50a485..5f2160e 100644 --- a/lib/Moo/_Utils.pm +++ b/lib/Moo/_Utils.pm @@ -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 (); @@ -58,6 +64,7 @@ our @EXPORT_OK = qw( _linear_isa _in_global_destruction _in_global_destruction_code + VERSION ); my %EXPORTS; @@ -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;