=== lib/MRO/Compat.pm
==================================================================
--- lib/MRO/Compat.pm (revision 4371)
+++ lib/MRO/Compat.pm (local)
@@ -170,22 +170,25 @@
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;
}
=== t/20mros.t
==================================================================
--- t/20mros.t (revision 4371)
+++ t/20mros.t (local)
@@ -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 @@
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 @@
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')",
+);