use warnings;
require 5.006_000;
+# Keep this < 1.00, so people can tell the fake
+# mro.pm from the real one
our $VERSION = '0.01';
BEGIN {
*mro::method_changed_in = \&__method_changed_in;
*mro::invalidate_all_method_caches
= \&__invalidate_all_method_caches;
+ $mro::VERSION = $VERSION;
+ $INC{'mro.pm'} = 'Faked by MRO::Compat';
}
# Provide no-op Class::C3::.*initialize() funcs for 5.9.5+
die q{Invalid mro type "$type"};
}
- # In the dfs case, check whether we need to
- # undo C3
+ # In the dfs case, check whether we need to undo C3
if(defined $Class::C3::MRO{$classname}) {
Class::C3::_remove_method_dispatch_table($classname);
}
--- /dev/null
+
+use strict;
+use warnings;
+
+use Test::More tests => 8;
+
+BEGIN {
+ use_ok('MRO::Compat');
+}
+
+{
+ package AAA; our @ISA = qw//; use mro 'dfs';
+ package BBB; our @ISA = qw/AAA/; use mro 'dfs';
+ package CCC; our @ISA = qw/AAA/; use mro 'dfs';
+ package DDD; our @ISA = qw/AAA/; use mro 'dfs';
+ package EEE; our @ISA = qw/BBB CCC DDD/; use mro 'dfs';
+ package FFF; our @ISA = qw/EEE DDD/; use mro 'dfs';
+ package GGG; our @ISA = qw/FFF/; use mro 'dfs';
+
+ package AAA3; our @ISA = qw//;
+ sub testsub { return $_[0] . '_first_in_dfs' }
+ package BBB3; our @ISA = qw/AAA3/;
+ package CCC3; our @ISA = qw/AAA3/;
+ sub testsub { return $_[0] . '_first_in_c3' }
+ package DDD3; our @ISA = qw/AAA3/;
+ package EEE3; our @ISA = qw/BBB3 CCC3 DDD3/;
+ package FFF3; our @ISA = qw/EEE3 DDD3/; use mro 'c3';
+ package GGG3; our @ISA = qw/FFF3/; use mro 'c3';
+}
+
+is_deeply(
+ mro::get_linear_isa('GGG'),
+ [ 'GGG', 'FFF', 'EEE', 'BBB', 'AAA', 'CCC', 'DDD' ],
+ "get_linear_isa for GGG",
+);
+
+is_deeply(
+ mro::get_linear_isa('GGG3'),
+ [ 'GGG3', 'FFF3', 'EEE3', 'BBB3', 'CCC3', 'DDD3', 'AAA3' ],
+ "get_linear_isa for GGG3",
+);
+
+is(FFF3->testsub(), 'FFF3_first_in_dfs', 'dfs resolution pre-init');
+
+Class::C3::initialize();
+
+is(FFF3->testsub(), 'FFF3_first_in_c3', 'c3 resolution post-init');
+
+mro::set_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_deeply(
+ mro::get_linear_isa('GGG3'),
+ [ 'GGG3', 'FFF3', 'EEE3', 'BBB3', 'CCC3', 'DDD3', 'AAA3' ],
+ "get_linear_isa for GGG3 (still c3)",
+);