From: Stevan Little Date: Sun, 4 Mar 2007 15:13:28 +0000 (+0000) Subject: Class::MOP::load_class change X-Git-Tag: 0_19~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1eaed09d0fda52d807cf1ba40d371e77bf660a1e;p=gitmo%2FMoose.git Class::MOP::load_class change --- diff --git a/Changes b/Changes index 3873598..91f5f5d 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Revision history for Perl extension Moose 0.18 ~~ Many documentation updates ~~ + + - We now use Class::MOP::load_class to + load all classes. 0.18_001 !! You must have Class::MOP 0.37_001 !! diff --git a/lib/Moose.pm b/lib/Moose.pm index dee59e9..95586ce 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -1,4 +1,16 @@ +use FindBin; +use File::Spec; +use lib File::Spec->catdir( + $FindBin::Bin, + File::Spec->updir, + File::Spec->updir, + File::Spec->updir, + 'Class-MOP', + 'trunk', + 'lib', +); + package Moose; use strict; @@ -71,7 +83,7 @@ use Moose::Util::TypeConstraints; my $class = $CALLER; return subname 'Moose::extends' => sub (@) { confess "Must derive at least one class" unless @_; - _load_all_classes(@_); + Class::MOP::load_class($_) for @_; # this checks the metaclass to make sure # it is correct, sometimes it can get out # of sync when the classes are being built @@ -84,7 +96,7 @@ use Moose::Util::TypeConstraints; return subname 'Moose::with' => sub (@) { my (@roles) = @_; confess "Must specify at least one role" unless @roles; - _load_all_classes(@roles); + Class::MOP::load_class($_) for @roles; $class->meta->_apply_all_roles(@roles); }; }, @@ -219,38 +231,6 @@ use Moose::Util::TypeConstraints; } -## Utility functions - -## TODO: -## replace these two with the -## Class::MOP:: versions now - -sub _load_all_classes { - foreach my $class (@_) { - # see if this is already - # loaded in the symbol table - next if _is_class_already_loaded($class); - # otherwise require it ... - my $file = $class . '.pm'; - $file =~ s{::}{/}g; - eval { CORE::require($file) }; - confess( - "Could not load module '$class' because : $@" - ) if $@; - } -} - -sub _is_class_already_loaded { - my $name = shift; - no strict 'refs'; - return 1 if defined ${"${name}::VERSION"} || defined @{"${name}::ISA"}; - foreach (keys %{"${name}::"}) { - next if substr($_, -2, 2) eq '::'; - return 1 if defined &{"${name}::$_"}; - } - return 0; -} - ## make 'em all immutable $_->meta->make_immutable( diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index df4daa4..6517877 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -274,7 +274,7 @@ sub _process_attribute { } else { if ($options{metaclass}) { - Moose::_load_all_classes($options{metaclass}); + Class::MOP::load_class($options{metaclass}); $self->add_attribute($options{metaclass}->new($name, %options)); } else { diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index 2ceb6a4..dc1867f 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -59,7 +59,7 @@ use Moose::Util::TypeConstraints; return subname 'Moose::Role::with' => sub (@) { my (@roles) = @_; confess "Must specify at least one role" unless @roles; - Moose::_load_all_classes(@roles); + Class::MOP::load_class($_) for @roles; ($_->can('meta') && $_->meta->isa('Moose::Meta::Role')) || confess "You can only consume roles, $_ is not a Moose role" foreach @roles; diff --git a/t/011_require_superclasses.t b/t/011_require_superclasses.t index f48540e..ced023f 100644 --- a/t/011_require_superclasses.t +++ b/t/011_require_superclasses.t @@ -41,6 +41,6 @@ BEGIN { eval { extends 'No::Class'; }; ::ok($@, '... could not find the superclass (as expected)'); - ::like($@, qr/^Could not load module 'No\:\:Class' because \:/, '... and got the error we expected'); + ::like($@, qr/^Could not load class \(No\:\:Class\) because \:/, '... and got the error we expected'); }