+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;
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
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);
};
},
}
-## 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(
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;
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');
}