From: Brandon L Black Date: Wed, 28 May 2008 23:35:20 +0000 (+0000) Subject: fix for RT#36256 X-Git-Tag: 0.09~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMRO-Compat.git;a=commitdiff_plain;h=fd0bf4907d5da3aeb7616c8d7fa524bf0a52499f fix for RT#36256 --- diff --git a/ChangeLog b/ChangeLog index bae1707..d404b0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ Revision history for Perl extension MRO::Compat. + - Add fixup (and new tests) for RT#36256 + 0.07 - Tue May 20, 2008 - Add explicit dependency on perl 5.6.0 or higher in Makefile.PL + META.yml diff --git a/lib/MRO/Compat.pm b/lib/MRO/Compat.pm index c6834ed..a1022a9 100644 --- a/lib/MRO/Compat.pm +++ b/lib/MRO/Compat.pm @@ -170,22 +170,25 @@ section for additional details. sub __set_mro { my ($classname, $type) = @_; + if(!defined $classname || !$type) { die q{Usage: mro::set_mro($classname, $type)}; } + if($type eq 'c3') { eval "package $classname; use Class::C3"; die $@ if $@; } - if($type ne 'dfs') { - die q{Invalid mro type "$type"}; + elsif($type eq 'dfs') { + # In the dfs case, check whether we need to undo C3 + if(defined $Class::C3::MRO{$classname}) { + Class::C3::_remove_method_dispatch_table($classname); + } + delete $Class::C3::MRO{$classname}; } - - # In the dfs case, check whether we need to undo C3 - if(defined $Class::C3::MRO{$classname}) { - Class::C3::_remove_method_dispatch_table($classname); + else { + die qq{Invalid mro type "$type"}; } - delete $Class::C3::MRO{$classname}; return; } diff --git a/t/20mros.t b/t/20mros.t index 0d3f3d9..e10eebe 100644 --- a/t/20mros.t +++ b/t/20mros.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => 14; BEGIN { use_ok('MRO::Compat'); @@ -28,6 +28,8 @@ BEGIN { package GGG3; our @ISA = qw/FFF3/; use mro 'c3'; } +is(mro::get_mro('FFF3'), 'c3'); + is_deeply( mro::get_linear_isa('GGG'), [ 'GGG', 'FFF', 'EEE', 'BBB', 'AAA', 'CCC', 'DDD' ], @@ -50,16 +52,33 @@ Class::C3::initialize(); is(FFF3->testsub(), 'FFF3_first_in_c3', 'c3 resolution post-init'); mro::set_mro('FFF3', 'dfs'); +is(mro::get_mro('FFF3'), 'dfs'); is_deeply( mro::get_linear_isa('FFF3'), [ 'FFF3', 'EEE3', 'BBB3', 'AAA3', 'CCC3', 'DDD3' ], "get_linear_isa for FFF3 (dfs)", ); -is(FFF3->testsub(), 'FFF3_first_in_dfs', 'dfs resolution post- setmro dfs'); +is(FFF3->testsub(), 'FFF3_first_in_dfs', 'dfs resolution post- set_mro dfs'); is_deeply( mro::get_linear_isa('GGG3'), [ 'GGG3', 'FFF3', 'EEE3', 'BBB3', 'CCC3', 'DDD3', 'AAA3' ], "get_linear_isa for GGG3 (still c3)", ); + +mro::set_mro('FFF3', 'c3'); +is(mro::get_mro('FFF3'), 'c3'); +is_deeply( + mro::get_linear_isa('FFF3'), + [ 'FFF3', 'EEE3', 'BBB3', 'CCC3', 'DDD3', 'AAA3' ], + "get_linear_isa for FFF3 (reset to c3 via set_mro)", +); + +eval "package FFF3; use mro 'dfs'"; +is(mro::get_mro('FFF3'), 'dfs'); +is_deeply( + mro::get_linear_isa('FFF3'), + [ 'FFF3', 'EEE3', 'BBB3', 'AAA3', 'CCC3', 'DDD3' ], + "get_linear_isa for FFF3 (reset to dfs via 'use mro')", +);