X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FUtil.pm;h=98dd1371284930a161166e83745f25d113f0204c;hp=a8196185089a5bff0b319ba0c297fcc53796b42c;hb=d67f600df9deb0deb95616f617c1aca3fd78a2e3;hpb=0ffc4183de68b15deeec5d662d9cc1d125dabf26 diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index a819618..98dd137 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -3,6 +3,18 @@ use Mouse::Exporter; # enables strict and warnings sub get_linear_isa($;$); # must be here +sub install_subroutines { # must be here + my $into = shift; + + while(my($name, $code) = splice @_, 0, 2){ + no strict 'refs'; + no warnings 'once', 'redefine'; + use warnings FATAL => 'uninitialized'; + *{$into . '::' . $name} = \&{$code}; + } + return; +} + BEGIN{ # This is used in Mouse::PurePerl Mouse::Exporter->setup_import_methods( @@ -48,6 +60,7 @@ BEGIN{ (my $hack_mouse_file = __FILE__) =~ s/.Util//; # .../Mouse/Util.pm -> .../Mouse.pm $xs = eval sprintf("#line %d %s\n", __LINE__, $hack_mouse_file) . q{ + local $^W = 0; # work around 'redefine' warning to &install_subroutines require XSLoader; XSLoader::load('Mouse', $VERSION); Mouse::Util->import({ into => 'Mouse::Meta::Method::Constructor::XS' }, ':meta'); @@ -121,7 +134,7 @@ BEGIN { require mro; $get_linear_isa = \&mro::get_linear_isa; } else { -# VVVVV CODE TAKEN FROM MRO::COMPAT VVVVV + # this code is based on MRO::Compat::__get_linear_isa my $_get_linear_isa_dfs; # this recurses so it isn't pretty $_get_linear_isa_dfs = sub { my($classname) = @_; @@ -131,8 +144,7 @@ BEGIN { no strict 'refs'; foreach my $parent (@{"$classname\::ISA"}) { - my $plin = $_get_linear_isa_dfs->($parent); - foreach my $p(@$plin) { + foreach my $p(@{ $_get_linear_isa_dfs->($parent) }) { next if exists $stored{$p}; push(@lin, $p); $stored{$p} = 1; @@ -140,24 +152,29 @@ BEGIN { } return \@lin; }; -# ^^^^^ CODE TAKEN FROM MRO::COMPAT ^^^^^ - eval{ require Class::C3 }; + { + package # hide from PAUSE + Class::C3; + our %MRO; # work around 'once' warnings + } # MRO::Compat::__get_linear_isa has no prototype, so # we define a prototyped version for compatibility with core's # See also MRO::Compat::__get_linear_isa. $get_linear_isa = sub ($;$){ my($classname, $type) = @_; - package # hide from PAUSE - Class::C3; + if(!defined $type){ - our %MRO; - $type = exists $MRO{$classname} ? 'c3' : 'dfs'; + $type = exists $Class::C3::MRO{$classname} ? 'c3' : 'dfs'; + } + if($type eq 'c3'){ + require Class::C3; + return [Class::C3::calculateMRO($classname)]; + } + else{ + return $_get_linear_isa_dfs->($classname); } - return $type eq 'c3' - ? [calculateMRO($classname)] - : $_get_linear_isa_dfs->($classname); }; }