Permalink
Browse files

finish removing the mro stuff (fixes #90)

  • Loading branch information...
1 parent 298b432 commit 247d5fa31cc1fc7c628612f59c82e78a9c1bb2ce @doy doy committed Oct 6, 2013
View
@@ -22,8 +22,6 @@ use mop::internals::observable;
use mop::internals::syntax;
use mop::internals::util;
-use mop::mro;
-
use mop::traits;
use mop::traits::util;
@@ -85,14 +83,14 @@ sub rebless {
my $from = Scalar::Util::blessed($object);
my $common_base = mop::internals::util::find_common_base($from, $into);
- my @from_isa = @{ mop::mro::get_linear_isa($from) };
+ my @from_isa = @{ mro::get_linear_isa($from) };
if ($common_base) {
pop @from_isa until $from_isa[-1] eq $common_base;
pop @from_isa;
}
@from_isa = grep { defined } map { meta($_) } @from_isa;
- my @into_isa = @{ mop::mro::get_linear_isa($into) };
+ my @into_isa = @{ mro::get_linear_isa($into) };
if ($common_base) {
pop @into_isa until $into_isa[-1] eq $common_base;
pop @into_isa;
@@ -119,7 +117,7 @@ sub dump_object {
if (my $m = meta($_)) {
%{ $m->attribute_map }
}
- } reverse @{ mop::mro::get_linear_isa($obj) };
+ } reverse @{ mro::get_linear_isa(ref $obj) };
my $temp = {
__ID__ => id($obj),
View
@@ -78,7 +78,7 @@ sub new_instance {
if (my $m = mop::meta($_)) {
%{ $m->attribute_map }
}
- } reverse @{ mop::mro::get_linear_isa($self->name) };
+ } reverse @{ mro::get_linear_isa($self->name) };
foreach my $attr (values %attributes) {
if ( exists $args{ $attr->key_name }) {
@@ -102,7 +102,7 @@ sub clone_instance {
if (my $m = mop::meta($_)) {
%{ $m->attribute_map }
}
- } reverse @{ mop::mro::get_linear_isa($self->name) }
+ } reverse @{ mro::get_linear_isa($self->name) }
};
%args = (
@@ -167,12 +167,12 @@ sub rebase_metaclasses {
my $common_base = find_common_base($meta_name, $super_name);
return unless $common_base;
- my @meta_isa = @{ mop::mro::get_linear_isa($meta_name) };
+ my @meta_isa = @{ mro::get_linear_isa($meta_name) };
pop @meta_isa until $meta_isa[-1] eq $common_base;
pop @meta_isa;
@meta_isa = reverse map { mop::meta($_) } @meta_isa;
- my @super_isa = @{ mop::mro::get_linear_isa($super_name) };
+ my @super_isa = @{ mro::get_linear_isa($super_name) };
pop @super_isa until $super_isa[-1] eq $common_base;
pop @super_isa;
@super_isa = reverse map { mop::meta($_) } @super_isa;
@@ -213,9 +213,9 @@ sub find_common_base {
my ($meta_name, $super_name) = @_;
my %meta_ancestors =
- map { $_ => 1 } @{ mop::mro::get_linear_isa($meta_name) };
+ map { $_ => 1 } @{ mro::get_linear_isa($meta_name) };
- for my $super_ancestor (@{ mop::mro::get_linear_isa($super_name) }) {
+ for my $super_ancestor (@{ mro::get_linear_isa($super_name) }) {
return $super_ancestor if $meta_ancestors{$super_ancestor};
}
View
@@ -1,44 +0,0 @@
-package mop::mro;
-
-use v5.16;
-use warnings;
-
-use Scalar::Util ();
-
-our $VERSION = '0.01';
-our $AUTHORITY = 'cpan:STEVAN';
-
-{
- my %ISA_CACHE;
-
- sub clear_isa_cache {
- my ($class) = ref($_[0]) || $_[0];
- delete $ISA_CACHE{$class};
- }
-
- sub get_linear_isa {
- my $class = ref($_[0]) || $_[0];
-
- return $ISA_CACHE{$class} if $ISA_CACHE{$class};
-
- my @isa;
- my $current = $class;
- while (defined $current) {
- if (my $meta = mop::meta($current)) {
- push @isa, $current;
- $current = $meta->superclass;
- }
- else {
- push @isa, @{ mro::get_linear_isa($current) };
- last;
- }
- }
- return $ISA_CACHE{$class} = \@isa;
- }
-
- # disable isa caching during global destruction, because things may have
- # started disappearing by that point
- END { %ISA_CACHE = () }
-}
-
-1;
View
@@ -33,7 +33,7 @@ sub clone {
sub BUILDALL {
my ($self, @args) = @_;
- foreach my $class (reverse @{ mop::mro::get_linear_isa($self) }) {
+ foreach my $class (reverse @{ mro::get_linear_isa(ref $self) }) {
if (my $m = mop::meta($class)) {
$m->get_method('BUILD')->execute($self, [ @args ])
if $m->has_method('BUILD');
@@ -43,7 +43,7 @@ sub BUILDALL {
sub does {
my ($self, $role) = @_;
- scalar grep { mop::meta($_)->does_role($role) } @{ mop::mro::get_linear_isa($self) }
+ scalar grep { mop::meta($_)->does_role($role) } @{ mro::get_linear_isa(ref($self) || $self) }
}
sub DOES {
@@ -53,7 +53,7 @@ sub DOES {
sub DESTROY {
my $self = shift;
- foreach my $class (@{ mop::mro::get_linear_isa($self) }) {
+ foreach my $class (@{ mro::get_linear_isa(ref $self) }) {
if (my $m = mop::meta($class)) {
$m->get_method('DEMOLISH')->execute($self, [])
if $m->has_method('DEMOLISH');
View
@@ -215,7 +215,7 @@ sub FINALIZE {
my @super_methods = (
map { $_ ? $_->get_method($method->name) : undef }
map { mop::meta($_) }
- @{ mop::mro::get_linear_isa($name) }
+ @{ mro::get_linear_isa($name) }
);
shift @super_methods;
@super_methods = grep { defined } @super_methods;
View
@@ -30,31 +30,31 @@ isa_ok('mop::method', 'mop::object');
isa_ok('mop::attribute', 'mop::object');
is_deeply(
- mop::mro::get_linear_isa('mop::class'),
+ mro::get_linear_isa('mop::class'),
[ 'mop::class', 'mop::object' ],
'... got the expected mro'
);
is_deeply(
- mop::mro::get_linear_isa('mop::role'),
+ mro::get_linear_isa('mop::role'),
[ 'mop::role', 'mop::object' ],
'... got the expected mro'
);
is_deeply(
- mop::mro::get_linear_isa('mop::method'),
+ mro::get_linear_isa('mop::method'),
[ 'mop::method', 'mop::object' ],
'... got the expected mro'
);
is_deeply(
- mop::mro::get_linear_isa('mop::attribute'),
+ mro::get_linear_isa('mop::attribute'),
[ 'mop::attribute', 'mop::object' ],
'... got the expected mro'
);
is_deeply(
- mop::mro::get_linear_isa('mop::object'),
+ mro::get_linear_isa('mop::object'),
[ 'mop::object' ],
'... got the expected mro'
);
@@ -81,4 +81,4 @@ is_deeply(
-done_testing;
+done_testing;
@@ -50,7 +50,7 @@ class Point3D extends Point {
isa_ok($p, 'Point');
is_deeply(
- mop::mro::get_linear_isa('Point'),
+ mro::get_linear_isa('Point'),
[ 'Point', 'mop::object' ],
'... got the expected linear isa'
);
@@ -74,7 +74,7 @@ class Point3D extends Point {
isa_ok($p3d, 'Point');
is_deeply(
- mop::mro::get_linear_isa('Point3D'),
+ mro::get_linear_isa('Point3D'),
[ 'Point3D', 'Point', 'mop::object' ],
'... got the expected linear isa'
);
@@ -67,13 +67,13 @@ is $checking->balance, 0, '... got the checking balance we expected';
is $savings->balance, 200, '... got the savings balance we expected';
is_deeply(
- mop::mro::get_linear_isa('BankAccount'),
+ mro::get_linear_isa('BankAccount'),
[ 'BankAccount', 'mop::object' ],
'... got the expected linear isa'
);
is_deeply(
- mop::mro::get_linear_isa('CheckingAccount'),
+ mro::get_linear_isa('CheckingAccount'),
[ 'CheckingAccount', 'BankAccount', 'mop::object' ],
'... got the expected linear isa'
);
View
@@ -27,7 +27,7 @@ class Foo {
}
is_deeply(
- mop::mro::get_linear_isa('Foo'),
+ mro::get_linear_isa('Foo'),
[ 'Foo', 'mop::object' ],
'... got the expected linear isa'
);
@@ -10,7 +10,7 @@ use lib 't/lib';
use_ok 'Level3', '... use Level3 works';
is_deeply(
- mop::mro::get_linear_isa('Level3'),
+ mro::get_linear_isa('Level3'),
[ 'Level3', 'Level2', 'Level1', 'Root', 'mop::object' ],
'... Level3 MRO contains all relevant classes'
);
@@ -44,13 +44,13 @@ is(Bar->hello, 'Object::hello', '... got the value we expected from Bar->hello')
is(Foo->hello, 'Object::hello', '... got the value we expected from Foo->hello');
is_deeply(
- mop::mro::get_linear_isa('Foo'),
+ mro::get_linear_isa('Foo'),
[ 'Foo', 'BaseObject' ],
'... got the expected linear isa'
);
is_deeply(
- mop::mro::get_linear_isa('Bar'),
+ mro::get_linear_isa('Bar'),
[ 'Bar', 'Foo', 'BaseObject' ],
'... got the expected linear isa'
);
@@ -56,7 +56,7 @@ is_deeply($e->manager, $m, '... got the expected manager');
#warn Dumper mop::meta('Employee');
is_deeply(
- mop::mro::get_linear_isa('Employee'),
+ mro::get_linear_isa('Employee'),
[ 'Employee', 'Person', 'Moose::Object' ],
'... got the expected linear isa'
);

0 comments on commit 247d5fa

Please sign in to comment.