RsrchBoy/moosex-abstractmethod — Issue #1: Intermediate abstract classes
Author: ausiasmarch
Created: 2012-02-22 16:07:05+00:00
State: open

Hello!

I have spotted what a believe is a limitation of the MooseX::AbstractMethod module.

As the check for abstract method implementation occurs whenever a subclass is made immutable, the creation of intermediate abstract classes, children of other abstract classes but which do not implement some of the abstract methods of their parents is not possible.

For instance, a situation as (in informal notation):

class A { abstract f() }
class B extends A { }
class C extends B { f() }

seems not to be implementable without explicitly repeating the declaration of f() as abstract within B.

I have experimented for a while, and I would like to propose a solution based on explicitly marking the B class as abstract, which might be more elegant. My suggestion would be to use something as:

```perl
{
package A;
use Moose;
use MooseX::AbstractMethod;
use namespace::autoclean;

abstract 'f';

__PACKAGE__->meta->make_immutable;
}

{
package B;
use Moose;
use MooseX::AbstractMethod qw( );
use namespace::autoclean;

extends 'A';

__PACKAGE__->meta->make_immutable;
}

{
package C;
use Moose;
use namespace::autoclean;

extends 'B';

sub f { print("f is called\n") }

__PACKAGE__->meta->make_immutable;
}
```

I include a patch with the implementation of this feature. The implementation works by incorporating an 'isAbstract' attribute to the metaclass, which is set to true explicitly by the import function or whenever an abstract method is added. The search for unimplemented abstract methods is only performed is the class is not abstract.

If you consider this change interesting for incorporation to the module, let me know and, if you want, I will be happy to discuss about the best way to do so. In particular, I am not sure if the

```perl
use MooseX::AbstractMethod qw( );
```

is the most suitable syntax, but it was the first thing that came to my mind.

Thank you!

Edgar