Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 45591
Status: open
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: ovid [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.76
Fixed in: (no value)



Subject: Excluded methods should be added to 'requires'
Consider the following code and the error message: #!/usr/bin/env perl package My::Role::Foo; use Moose::Role; sub foo { 'foo' } package My::Class; use Moose; with 'My::Role::Foo' => { excludes => ['foo'] }; print My::Class->foo; The error message is: Can't locate object method "foo" via package "My::Class" at role.pl line 12. The problem that since My::Class->meta->does('My::Role::Foo'), there's a promise that it will provide the &foo method. However, the failure happens at runtime, not at composition time. I'm expecting a composition-time error message like this: My::Role::Foo' requires the method 'foo' to be implemented by 'My::Class' at ... I think the solution is to have Moose::Meta::Role::add_excluded_methods also call ->add_required_methods with the same argument list, but I've not tested this. Cheers, Ovid
On Thu Apr 30 06:30:57 2009, OVID wrote: Show quoted text
> I think the solution is to have Moose::Meta::Role::add_excluded_methods > also call ->add_required_methods with the same argument list, but I've > not tested this.
We had a long discussion about this on #moose-dev. We agree that the allomorphic aspects of Roles are important, but this kind of a change isn't trivial. It would be best if we used a long deprecation process to introduce something like this where we can measure the kind of impact it would make. Sartak suggested creating a Perl::Critic::Dynamic::Moose module that would warn about violating the Allomorphism. I think that would be an excellent first step in this kind of a process because it would be able to identify how much existing code violates this best practice, then a MooseX:: similar to MooseX::StrictConstructors could be created to enable this feature and test it's impact going forward. -Chris
On Thu Apr 30 06:30:57 2009, OVID wrote: Show quoted text
> The problem that since My::Class->meta->does('My::Role::Foo'), there's a > promise that it will provide the &foo method. However, the failure > happens at runtime, not at composition time. I'm expecting a > composition-time error message like this:
So the timescale is Compile-time < Composition-time < Run-time ? What you are describing would be possible if Moose was reflecting on its own code trying to find which methods are needed and if this contradicts the excluded methods. -- Your bugs , they are afraid of me.