push @missing, $required_method_name;
}
- else {
- # NOTE:
- # we need to make sure that the method is
- # not a method modifier, because those do
- # not satisfy the requirements ...
- my $method = $class->find_method_by_name($required_method_name);
-
- # check if it is a generated accessor ...
- push @is_attr, $required_method_name,
- if $method->isa('Class::MOP::Method::Accessor');
-
- # NOTE:
- # All other tests here have been removed, they were tests
- # for overriden methods and before/after/around modifiers.
- # But we realized that for classes any overriden or modified
- # methods would be backed by a real method of that name
- # (and therefore meet the requirement). And for roles, the
- # overriden and modified methods are "in statis" and so would
- # not show up in this test anyway (and as a side-effect they
- # would not fufill the requirement, which is exactly what we
- # want them to do anyway).
- # - SL
- }
}
- return unless @missing || @is_attr;
+ return unless @missing;
my $error = '';
. $class->name . q{'};
}
- if (@is_attr) {
- my $noun = @is_attr == 1 ? 'method' : 'methods';
-
- my $list
- = Moose::Util::english_list( map { q{'} . $_ . q{'} } @is_attr );
-
- $error .= "\n" if length $error;
-
- $error
- .= q{'}
- . $role->name
- . "' requires the $noun $list "
- . "to be implemented by '"
- . $class->name
- . "' but the method is only an attribute accessor";
- }
-
$class->throw_error($error);
}
has 'meth2' => ( is => 'ro' );
::throws_ok { with('Quux::Role') }
- qr/\Q'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class3'\E\n
- \Q'Quux::Role' requires the methods 'meth1' and 'meth2' to be implemented by 'Quux::Class3' but the method is only an attribute accessor/x,
- 'exception mentions all the require methods that are accessors at once, as well as missing methods';
+ qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class3'/,
+ 'exception mentions all the missing methods at once, but not the accessors';
}
{
has 'meth2' => ( is => 'ro' );
::throws_ok { with('Quux::Role') }
- qr/\Q'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class4'\E\n
- \Q'Quux::Role' requires the method 'meth2' to be implemented by 'Quux::Class4' but the method is only an attribute accessor/x,
+ qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class4'/,
'exception mentions all the require methods that are accessors at once, as well as missing methods, but not the one that exists';
}
has 'foo' => (is => 'ro');
- ::dies_ok {
+ ::lives_ok {
with 'Role::RequireFoo';
- } '... the required "foo" method exists, but it is a before (and we will die)';
+ } '... the required "foo" method exists, and is an accessor';
}
# ...
use Moose;
extends 'Foo::Class::Base';
- ::dies_ok {
+ ::lives_ok {
with 'Foo::Role';
} '... our role combined successfully';
}
} "define role Role::I";
sub zot { 'Role::I::zot' }
+ sub zzy { 'Role::I::zzy' }
package Class::C;
use Moose;
ok(Role::I->meta->requires_method('foo'), '... Role::I still have the &foo requirement');
{
- # fix these later ...
- TODO: {
- local $TODO = "add support for attribute methods fufilling reqs";
+ lives_ok {
+ package Class::D;
+ use Moose;
- lives_ok {
- package Class::D;
- use Moose;
+ has foo => ( default => __PACKAGE__ . "::foo", is => "rw" );
- has foo => ( default => __PACKAGE__ . "::foo", is => "rw" );
+ sub zot { 'Class::D::zot' }
- sub zot { 'Class::D::zot' }
+ with qw(Role::I);
- with qw(Role::I);
-
- } "resolved with attr";
+ } "resolved with attr";
- can_ok( Class::D->new, qw(foo bar xxy zot) );
- is( eval { Class::D->new->bar }, "Role::H::bar", "bar" );
- is( eval { Class::D->new->xxy }, "Role::I::xxy", "xxy" );
- }
+ can_ok( Class::D->new, qw(foo bar xxy zot) );
+ is( eval { Class::D->new->bar }, "Role::H::bar", "bar" );
+ is( eval { Class::D->new->zzy }, "Role::I::zzy", "zzy" );
is( eval { Class::D->new->foo }, "Class::D::foo", "foo" );
is( eval { Class::D->new->zot }, "Class::D::zot", "zot" );
has twist => ( is => "rw" );
{
- local our $TODO = "accessors don't satisfy role requires";
::lives_ok { with qw(Dancer) };
}