require File::Spec;
require File::Basename;
+ print "Creating xt/compatibility/* ...\n";
+
# some test does not pass... currently skip it.
my %SKIP_TEST = (
'016-trigger.t' => "trigger's argument is incompatble :(",
'020-load-class.t' => "&Moose::is_class_loaded doesn't exists",
'019-handles.t' => 'incompatible',
- '025-more-isa.t' => 'Class::MOP::is_class_loaded is not compatible with Mouse::is_class_loaded',
'029-new.t' => 'Class->new(undef) incompatible',
'010-isa-or.t' => 'Mouse has a [BUG]',
'044-attribute-metaclass.t' => 'Moose::Meta::Attribute does not have a "create"',
'047-attribute-metaclass-role.t' => 'Moose::Meta::Attribute does not have a "create"',
'201-squirrel.t' => 'skip Squirrel',
'202-squirrel-role.t' => 'Squirrel is ...',
- '400-define-role.t' => 'incompatibility',
'600-tiny-tiny.t' => "Moose doesn't support ::Tiny",
'601-tiny-mouse.t' => "Moose doesn't support ::Tiny",
'602-mouse-tiny.t' => "Moose doesn't support ::Tiny",
- '031_roles_applied_in_create.t' => 'wtf?',
+ '031_roles_applied_in_create.t' => 't/lib/* classes are not Moose classes/roles',
);
File::Find::find(
{
wanted => sub {
return unless -f $_;
+
+ return if /failing/; # skip tests in failing/ directories
+
my $basename = File::Basename::basename($_);
return if $basename =~ /^\./;
return if $SKIP_TEST{$basename};
-
+
my $dirname = File::Basename::dirname($_);
my $tmpdir = File::Spec->catfile('xt', 'compatibility', $dirname);
next unless $meta && $meta->can('roles');
for my $role (@{ $meta->roles }) {
+
return 1 if $role->does_role($role_name);
}
}
|| $class->throw_error("You must pass a HASH ref of methods")
if exists $options{methods};
+ (ref $options{roles} eq 'ARRAY')
+ || $class->throw_error("You must pass an ARRAY ref of roles")
+ if exists $options{roles};
+
{
( defined $package_name && $package_name )
|| $class->throw_error("You must pass a package name");
superclasses
attributes
methods
+ roles
version
authority
)};
$meta->add_method($method_name, $options{methods}->{$method_name});
}
}
+ if (exists $options{roles}){
+ Mouse::Util::apply_all_roles($package_name, @{$options{roles}});
+ }
return $meta;
}
use Scalar::Util 'blessed';
use Mouse::Meta::Role;
-use Mouse::Util;
+use Mouse::Util qw(load_class);
our @EXPORT = qw(before after around super override inner augment has extends with requires excludes confess blessed);
our %is_removable = map{ $_ => undef } @EXPORT;
$meta->add_attribute($name => \%opts);
}
-sub extends { confess "Roles do not currently support 'extends'" }
+sub extends { confess "Roles do not support 'extends'" }
sub with {
my $meta = Mouse::Meta::Role->initialize(scalar caller);
- my $role = shift;
- my $args = shift || {};
- confess "Mouse::Role only supports 'with' on individual roles at a time" if @_ || !ref $args;
-
- Mouse::load_class($role);
- $role->meta->apply($meta, %$args);
+ Mouse::Util::apply_all_roles($meta->name, @_);
}
sub requires {
return 0 if ref($class) || !defined($class) || !length($class);
- return 1 if exists $is_class_loaded_cache{$class};
+ return 1 if $is_class_loaded_cache{$class};
# walk the symbol table tree to avoid autovififying
# \*{${main::}{"Foo::"}} == \*main::Foo::
- my $pack = \*::;
+ my $pack = \%::;
foreach my $part (split('::', $class)) {
- return 0 unless exists ${$$pack}{"${part}::"};
- $pack = \*{${$$pack}{"${part}::"}};
+ my $entry = \$pack->{$part . '::'};
+ return 0 if ref($entry) ne 'GLOB';
+ $pack = *{$entry}{HASH} or return 0;
}
# check for $VERSION or @ISA
- return ++$is_class_loaded_cache{$class} if exists ${$$pack}{VERSION}
- && defined *{${$$pack}{VERSION}}{SCALAR};
- return ++$is_class_loaded_cache{$class} if exists ${$$pack}{ISA}
- && defined *{${$$pack}{ISA}}{ARRAY};
+ return ++$is_class_loaded_cache{$class} if exists $pack->{VERSION}
+ && defined *{$pack->{VERSION}}{SCALAR} && defined ${ $pack->{VERSION} };
+ return ++$is_class_loaded_cache{$class} if exists $pack->{ISA}
+ && defined *{$pack->{ISA}}{ARRAY} && @{ $pack->{ISA} } != 0;
# check for any method
- foreach ( keys %{$$pack} ) {
- next if substr($_, -2, 2) eq '::';
- return ++$is_class_loaded_cache{$class} if defined *{${$$pack}{$_}}{CODE};
+ foreach my $name( keys %{$pack} ) {
+ my $entry = \$pack->{$name};
+ return ++$is_class_loaded_cache{$class} if ref($entry) ne 'GLOB' || defined *{$entry}{CODE};
}
# fail
} else {
push @roles, [ $_[$i] => {} ];
}
+ my $role_name = $roles[-1][0];
+ load_class($role_name);
+ ( $role_name->can('meta') && $role_name->meta->isa('Mouse::Meta::Role') )
+ || $meta->throw_error("You can only consume roles, $role_name(".$role_name->meta.") is not a Mouse role");
}
- foreach my $role_spec (@roles) {
- Mouse::load_class( $role_spec->[0] );
- }
-
- ( $_->[0]->can('meta') && $_->[0]->meta->isa('Mouse::Meta::Role') )
- || confess("You can only consume roles, "
- . $_->[0]
- . " is not a Moose role")
- foreach @roles;
-
if ( scalar @roles == 1 ) {
my ( $role, $params ) = @{ $roles[0] };
$role->meta->apply( $meta, ( defined $params ? %$params : () ) );
);
};
-for ('B'..'E', 'G::H') {
+for ('B', 'D'..'E', 'G::H') {
lives_ok {
ClassNameTests->new(class => $_);
};
};
}
-TODO: {
- local $TODO = "Moose throws errors here. Mouse does not";
- throws_ok {
- ClassNameTests->new(class => 'A');
- } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value A/;
+throws_ok {
+ ClassNameTests->new(class => 'A');
+} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value A/;
- throws_ok {
- my $obj = ClassNameTests->new;
- $obj->class('A');
- } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value A/;
-}
+throws_ok {
+ my $obj = ClassNameTests->new;
+ $obj->class('A');
+} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value A/;
+
+throws_ok {
+ ClassNameTests->new(class => 'C');
+} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value C/;
+
+throws_ok {
+ my $obj = ClassNameTests->new;
+ $obj->class('C');
+} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value C/;
for ('F', 'G', 'I', 'Z') {
throws_ok {
extends 'Role::Parent';
no Mouse::Role;
-} qr/Roles do not currently support 'extends'/;
+} qr/Roles do not support 'extends'/;
lives_ok {
package Role;
::is(blessed($obj), "Impromptu::Class");
};
-our $TODO = 'skip';
-throws_ok {
+lives_ok{
package Class;
use Mouse;
with 'Role', 'Other::Role';
-} qr/Mouse::Role only supports 'with' on individual roles at a time/;
+};